【发布时间】:2015-05-20 22:15:21
【问题描述】:
看起来相当基本的东西对我来说无法正常工作。我只是想在仪表板上显示公告列表,但我的助手似乎没有从出版物中提取数据。我的文件在下面。
publications.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。我检查了数据库,可以看到可用的记录。另外,我没有收到任何关于电话的错误。
非常感谢任何帮助、建议等。
【问题讨论】:
-
您是否正确订阅?在控制台尝试 Announcements.find().fetch() 看看它是否返回空数组
-
谢谢@Sindis。看起来我没有正确获取。通过下面的 lehtu,我错过了订阅。
标签: javascript meteor