流星助手在每个循环中都不能工作
Meteor helpers not working in each loop
看起来相当基本的东西对我来说不能正常工作。我只是想在仪表板上显示一个公告列表,但是我的助手似乎没有从发布中提取数据。我的文件在下面
publications.js
Meteor.publish('announcements', function() {
return Announcements.find();
});
模板JS (dashboard.js):
Template.sendersDashboard.helpers({
announcements: function() {
return Announcements.find({}, {sort: {createdAt: -1}});
}
})
View 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}}
案例。我已经查了数据库,可以看到可用的记录。另外,我没有收到任何关于电话的错误。
如有任何帮助、建议等,不胜感激。
就像Sindis建议的那样,您可能错过了dashboard.js中的订阅。
Meteor.subscribe('announcements');
或者另一件事可能是你在错误的模板中有帮助。而不是:
Template.sendersDashboard.helpers({...
你应该有:
Template.dashboard_announcements.helpers({...
你的JS和HTML中有不同的模板名称:
你的模板名称在JS是sendersDashboard
:
Template.sendersDashboard.helpers({
//code
});
和你的模板名称在HTML是dashboard_announcements
:
<template name="dashboard_announcements">
<!-- code -->
</template>
我建议使用camelCase的模板名,所以修复HTML名称:
<template name="sendersDashboard">
<!-- code -->
</template>
相关文章:
- Mustache.js每个循环都不起作用
- 为什么我所有的循环都不起作用
- CSS-转换在JavaScript for循环中不能正常工作
- q.所有的功能都不能像我希望的那样工作
- Jquery行中的每个循环都不起作用
- 蓝鸟 摩卡中的每个循环都不起作用
- 对于 NodeJS 中的循环,不能与 Redis Hexists 一起工作
- 当遍历具有动态类名的元素时,每个循环都不起作用
- 为什么'我的两个脚本都不能在html中工作
- D3条形图在所有负值和正值情况下都不能正常工作
- jQuery detach()和remove()都不能处理附加元素
- jQuery .offset()在所有浏览器中都不能正常工作
- 循环内容不能正确显示
- PHP:我的按钮在foreach循环中不能正常工作
- 成功和错误都不能在jquery ajax中工作
- 为什么在JavaScript中所有东西都不能赋值?
- 所有问题都不能按正确的顺序解决
- 所有由JQuery选择的Primefaces复选框都不能正常工作
- jQuery.每个都不能在窗口中工作.onbeforeunload函数
- 流星助手在每个循环中都不能工作