TypeError:Employees.find不是meteor withTracker的函数

时间:2018-05-03 06:44:23

标签: reactjs meteor

首先使用createContainer来订阅数据,但它会抛出名为:

的错误
Uncaught TypeError: CreateContainer is not a function 

react-meteor-data: React higher-order component for reactively tracking Meteor data 

Warning - createContainer was deprecated in react-meteor-data@0.2.13. Use withTracker instead 

然后改为withTracker但收到错误:

Uncaught TypeError: Employees.find is not a function

Employee_list.js

import React from 'react';
import Employees from '../../imports/collections/employees';
import { withTracker } from 'meteor/react-meteor-data';

const EmployeeList = (props) => {
    console.log(props);
    return(
        <div>
            <div className = "employee-list">
                Employee list
            </div>
        </div>
    )
}

export default withTracker ( () => {

    const handle = Meteor.subscribe('employees');
    //return { employeesd: Employees.find({}).fetch() };
    return {
        listLoading: !handle.ready(),
        tasks: Employees.find({}).fetch(),
      };
})( EmployeeList );

员工是我的mongodb集合

employees.js

import { Mongo } from 'meteor/mongo';    
export const Employees = new Mongo.Collection('employees');

1 个答案:

答案 0 :(得分:0)

您使用命名导出:

export const Employees = new Mongo.Collection('employees');

但尝试使用默认导出:

import Employees from '../../imports/collections/employees';

<强>修正:

import { Employees } from '../../imports/collections/employees';

const Employees = new Mongo.Collection('employees');
export default Employees;