2016-09-01 81 views
0

這顆流星陣營的客戶端代碼產生器控制檯錯誤:未定義的集合名稱流星與之反應

ReferenceError: CarsCol is not defined

任何想法,爲什麼?由於

//cars.jsx 

import React from 'react'; 
import ReactDOM from 'react-dom'; 
import { composeWithTracker } from 'react-komposer'; 
import { ListItems } from '../containers/myList.jsx'; 

const composer = (props, onData) => { 
    const sub = Meteor.subscribe('carsCol'); 
    if (sub.ready()) { 
    const cars = CarsCol.find().fetch(); //<------- error line 
    onData(null, {cars}); 
    } 
}; 

const Container = composeWithTracker(composer) (ListItems); 
ReactDOM.render(<Container />, document.getElementById('react-root')); 


//publications.js 

const CarsCol = new Mongo.Collection('carsCol'); 
Meteor.publish('carsCol', function(){ 
    return CarsCol.find(); 
}); 

enter image description here

回答

0

你的服務器上定義的集合而已,要在兩地定義集合。

我會做的是在一個單獨的文件中定義你的集合並導入它。

/API /集合/ CarsCol

const CarsCol = new Mongo.Collection('carsCol'); 

然後在cars.jsx

import CarsCol from '../api/collections/CarsCol'