我试图从流星中的集合中获取信息,并使用帮助程序将其传递给模板。
这是我在server.js上的代码:
Meteor.publish('dataForTableD1', function () { return Day1.find( { period: 1 } ); });这是我在client.js上的代码:
Template.timetable.helpers({ 'day1p1': function() { Meteor.subscribe('dataForTableD1'); } });这是模板代码:
{#with day1p1}} <td>{{lesson}}</td> {{/with}}问题是它不会在渲染页面中显示任何内容。
我相信这可能是一个错字或类似的东西,因为我对流星很新,所以任何帮助将不胜感激。
I am trying to get information from a collection in meteor and using a helper passing it to a template.
Here is my code on server.js:
Meteor.publish('dataForTableD1', function () { return Day1.find( { period: 1 } ); });Here is my code on client.js:
Template.timetable.helpers({ 'day1p1': function() { Meteor.subscribe('dataForTableD1'); } });Here is the template code:
{#with day1p1}} <td>{{lesson}}</td> {{/with}}The problem is that it won't display anything in the rendered page.
I am sure this is probably a typo or something similar on my part as I am quite new to meteor so any help would be appreciated.
最满意答案
您只是订阅了dataForTableD1但是您没有在day1p1帮助函数中返回数据。 您可能希望使用collection.findOne([selector], [options])来返回与选择器匹配的文档。
请试试这个:
Template.timetable.helpers({ 'day1p1': function() { Meteor.subscribe('dataForTableD1'); return Day1.findOne(); // add here your selector and options } });You are just subscribing to dataForTableD1 but you don't return data in your day1p1 helper function. You probably want to use collection.findOne([selector], [options]) to return a document that matches a selector.
Please try this:
Template.timetable.helpers({ 'day1p1': function() { Meteor.subscribe('dataForTableD1'); return Day1.findOne(); // add here your selector and options } });更多推荐
发布评论