【发布时间】:2018-10-24 13:42:04
【问题描述】:
我是 Meteor 的新手,当我尝试显示 mongodb 集合中的项目列表时遇到此错误。
这些是我试图从我的 rewards 集合中检索的数据
这是我的代码:
服务器/publications.js
Rewards = new Mongo.Collection('rewards');
Meteor.publish('allRewards', function () {
if (this.userId) {
return Rewards.find({}, {
fields: {
'title': 1,
'headline': 1,
'summary': 1,
'description': 1,
'requirements': 1
}
})
} else {
this.ready()
}
});
lib/router.js
Router.route('/rewards', function () {
var selfRoute = this;
var rew = RewardsSubs.subscribe("allRewards");
document.title = "Rewards"
Tracker.autorun(function (computation) {
if (RewardsSubs.ready()) {
selfRoute.render('rewards', {
data: function () {
return {
rewards: rew
};
}
});
computation.stop()
} else {
selfRoute.render('loading');
}
});
});
客户端/启动/default.js
RewardsSubs = new SubsManager({
// maximum number of cache subscriptions
cacheLimit: 10,
// any subscription will be expire after 5 minute, if it's not subscribed again
expireIn: 10
});
client/templates/rewards/rewards.html
<template name="rewards">
<div class="ui container">
<table class="ui very basic table">
<tbody>
{{#each rewards}}
<tr>
<td>
<span>{{title}}</span>
</td>
<td>
<h4 class="ui image header">
<div class="content">
<div class="header">
. <span>{{headline}}</span>
. <span>{{summary}}</span>
</div>
</div>
</h4>
</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
</template>
我不知道为什么我有这个“{{#each}} 当前只接受数组、游标或错误值。”...感谢任何帮助解决这个问题。
【问题讨论】:
-
你的模板代码在哪里?
-
无论如何,我认为你的回报 { 奖励:rew };应该是 return { reward: Rewards.find() };
-
对,对不起,我忘记了。我刚刚添加了模板。关于您的第二条评论,我已尝试使用
ReferenceError: Rewards is not defined,但出现“ReferenceError:未定义奖励”。这个Rewards不是指我在publications.js中定义的集合吗?
标签: meteor