Javascript Meteor中未定义集合错误

Javascript Meteor中未定义集合错误,javascript,meteor,Javascript,Meteor,我一直在犯错误 模板帮助程序中的异常:引用错误:未定义线程 在尝试遍历集合并将其打印到页面中时。为了隔离问题,我将其设置为为为数据库中预加载的两个线程中的每个线程打印一个按钮。我收到错误,没有按钮被张贴。键入Threads.find().count();在控制台中返回2 我的代码如下 Meteor.startup(function () { Threads = new Mongo.Collection('threads'); }); Template.threads.helpers({

我一直在犯错误

模板帮助程序中的异常:引用错误:未定义线程

在尝试遍历集合并将其打印到页面中时。为了隔离问题,我将其设置为为为数据库中预加载的两个线程中的每个线程打印一个按钮。我收到错误,没有按钮被张贴。键入Threads.find().count();在控制台中返回2

我的代码如下

Meteor.startup(function () {
    Threads = new Mongo.Collection('threads');
});

Template.threads.helpers({
    threads: function() {
        return Threads.find();
    }
});


{{>线程}
{{{#每个线程}
按钮
{{/每个}}

尝试将收藏声明移出Meteor.startup块

我怀疑您的模板助手是在Meteor.startup启动之前首先调用的,因此引发了未定义的标识符错误。

是的--我的印象是,
Meteor.startup
启动之前启动。这就是解决办法。
<body>
    <div class="threads">
        {{> threads}}
    </div>
</body>

<template name="threads">
    {{#each threads}}
          <button>Button!</button>
    {{/each}}
</template>