未定义的集合名称Meteor with React

时间:2016-09-01 17:02:32

标签: meteor reactjs

此Meteor React客户端代码产生浏览器控制台错误:

  

ReferenceError:未定义CarsCol

知道为什么吗?感谢

//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

1 个答案:

答案 0 :(得分:0)

您已经在服务器上定义了集合,您想在两个地方定义集合。

我要做的是在一个单独的文件中定义你的集合并导入它。

/ API /集合/ CarsCol

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

然后在cars.jsx

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