【问题标题】:Uncaught Reference Error: collection is not defined---in meteor app未捕获的参考错误:集合未定义---在流星应用程序中
【发布时间】:2017-07-30 15:41:53
【问题描述】:

这是位于我的流星项目的 imports/ui 中的 .js 文件。

    import React from 'react';
    import {Tasks} from './../api/tc';

    export default class Task extends React.Component{
   render(){
return(

 <div key={this.props.task._id} className='item'>
    <p>
    {this.props.task.name}
    </p>
    <p className='prioritypoints'>
    priority level : {this.props.task.score}
    </p>
    <button className='button button--round' onClick={() => tc.remove({_id: this.props.task._id})}>X</button>
    <button className='button button--round' onClick={()=>
    tc.update({_id: this.props.task._id}, {$inc: {score:1}})}>
    +1</button>
    <button className='button button--round' onClick={()=>
    {tc.update({_id: this.props.task._id},{$inc: {score:-1}})}}>
    -1</button>

    </div>
);
      }
    };

“tc”是我在 imports/api/tc 中定义的 mongoDB 集合的名称。按钮的 onClick 事件没有响应,因为根据控制台未定义 task_collection。

tc.js:

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

为什么我在这个文件中导入了集合之后还是会出现这样的问题?

【问题讨论】:

    标签: javascript mongodb reactjs meteor minimongo


    【解决方案1】:

    不应该是 tc.remove,应该是 Tasks.remove({_id: this.props.tasks.id});

    您的所有查询都在 Tasks 上运行,因为它是 Mongo.Collection 的实例而不是 tc,tc 是您的数据库名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-31
      • 2016-10-03
      • 2020-08-31
      • 1970-01-01
      • 1970-01-01
      • 2017-01-02
      • 2021-12-08
      • 1970-01-01
      相关资源
      最近更新 更多