我想跟着流星文档浏览: https://www.meteor.com/tutorials/blaze/collections 中加入了收集,并能够在控制台这样做是为了得到一个空数组回:为什么我继续获取未定义的任务?
Tasks.find().fetch()
,而是我得到这个:
Uncaught ReferenceError: Tasks is not defined
at <anonymous>:1:1
我不确定自从我遵循他们的文档以来我出错了,我相信我根据文档创建的imports文件夹的树结构是正确的,并且我迄今为止实现的代码是我的也正如他们的文档所建议的那样。
这是客户端/ main.js:
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import {Tasks} from '../imports/api/tasks';
import './main.html';
Template.hello.onCreated(function helloOnCreated() {
// counter starts at 0
this.counter = new ReactiveVar(0);
});
// templates can have helpers which are just functions and events and this
// particular event is a click event
Template.todos.helpers({
tasks() {
return Tasks.find({});
},
});
Template.todos.events({
});
这是进口/ API/tasks.js:
import {Mongo} from 'meteor/mongo';
export const Tasks = new Mongo.Collection('tasks');
这是服务器/ main.js:
import { Meteor } from 'meteor/meteor';
import {Tasks} from '../imports/api/tasks';
Meteor.startup(() => {
// code to run on server at startup
});
这是客户端/ main.html:
<head>
<title>tasklist</title>
</head>
<body>
<h1>Welcome to Meteor!</h1>
{{> todos}}
{{> info}}
</body>
<template name="todos">
</template>
<template name="info">
<h2>Learn Meteor!</h2>
<ul>
<li><a href="https://www.meteor.com/try" target="_blank">Do the Tutorial</a></li>
<li><a href="http://guide.meteor.com" target="_blank">Follow the Guide</a></li>
<li><a href="https://docs.meteor.com" target="_blank">Read the Docs</a></li>
<li><a href="https://forums.meteor.com" target="_blank">Discussions</a></li>
</ul>
</template>
当您导入任务时它可能是缺少'.js'吗? – LPL