看起来相当基本的东西对我来说并不能正常工作。我只是想在仪表板上显示公告列表,但我的助手似乎没有从出版物中提取数据。我的文件如下。
出版物.js
Meteor.publish('announcements', function() {
return Announcements.find();
});
模板 JS(dashboard.js):
Template.sendersDashboard.helpers({
announcements: function() {
return Announcements.find({}, {sort: {createdAt: -1}});
}
})
查看JS(dashboard.html):
<template name="dashboard_announcements">
{{#each announcements}}
{{> single_announcement}}
{{else}}
There are no Announcements to display.
<br>
<h5><a href="{{pathFor 'newAnnouncement'}}">Why don't you make one now?</a></h5>
{{/each}}
</template>
当我在浏览器中查看页面时,我只看到 {{else}}
case。我已经检查了数据库并可以看到可用的记录。另外,我没有收到任何有关通话的错误。
非常感谢任何帮助、建议等。
最佳答案
就像 Sindis 所建议的那样,您可能会在仪表板.js 中缺少订阅。
Meteor.subscribe('announcements');
或者另一件事可能是您的助手使用了错误的模板。而不是:
Template.sendersDashboard.helpers({...
你应该有:
Template.dashboard_announcements.helpers({...
关于javascript - Meteor 助手不在每个循环中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30351679/