【发布时间】:2017-02-09 20:52:45
【问题描述】:
我正在尝试在此处遵循 Meteor 文档: https://www.meteor.com/tutorials/blaze/collections 在添加一个集合并能够通过在控制台中执行此操作来获取一个空数组:
Tasks.find().fetch()
但是我得到了这个:
Uncaught ReferenceError: Tasks is not defined
at <anonymous>:1:1
由于我正在关注他们的文档,因此我不确定我哪里出错了,我相信我根据文档创建的导入文件夹的树结构是正确的,并且我到目前为止实现的代码也如建议的那样他们的文档。
这是客户端/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?
标签: javascript meteor meteor-blaze