I keep getting the error
我一直在收到错误
Exception in template helper: ReferenceError: Threads is not defined
模板助手中的异常:ReferenceError:未定义线程
while trying to iterate through a collection and print it into the page. To isolate the problem I have set it to print a button for each of the two threads I have preloaded in the database. I receive the error and no buttons are posted. Typing Threads.find().count(); in the console returns 2.
在尝试迭代集合并将其打印到页面中时。为了隔离问题,我已将其设置为为数据库中预加载的两个线程中的每个线程打印一个按钮。我收到错误,没有发布任何按钮。键入Threads.find()。count();在控制台中返回2。
My code is as follows
我的代码如下
Meteor.startup(function () {
Threads = new Mongo.Collection('threads');
});
Template.threads.helpers({
threads: function() {
return Threads.find();
}
});
And
<body>
<div class="threads">
{{> threads}}
</div>
</body>
<template name="threads">
{{#each threads}}
<button>Button!</button>
{{/each}}
</template>
1 个解决方案
#1
Try moving your collection declaration out of the Meteor.startup
block.
尝试将您的集合声明移出Meteor.startup块。
I suspect that your template helper is first called before Meteor.startup
fires, thus provoking the undefined identifier error.
我怀疑在Meteor.startup触发之前首先调用模板助手,从而引发未定义的标识符错误。
#1
Try moving your collection declaration out of the Meteor.startup
block.
尝试将您的集合声明移出Meteor.startup块。
I suspect that your template helper is first called before Meteor.startup
fires, thus provoking the undefined identifier error.
我怀疑在Meteor.startup触发之前首先调用模板助手,从而引发未定义的标识符错误。