Meteor 未显示 html 中的集合信息
Meteor not displaying information from collection in html
我正在尝试从 meteor 中的集合中获取信息并使用助手将其传递给模板。
这是我在 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}}
问题是它不会在呈现的页面中显示任何内容。
我确信这可能是我的错字或类似的东西,因为我对 meteor 很陌生,所以任何帮助将不胜感激。
您只是订阅了 dataForTableD1
,但您没有 return 数据到您的 day1p1
辅助函数中。您可能想使用 collection.findOne([selector], [options])
到 return 匹配选择器的文档。
请试试这个:
Template.timetable.helpers({
'day1p1': function() {
Meteor.subscribe('dataForTableD1');
return Day1.findOne(); // add here your selector and options
}
});
我正在尝试从 meteor 中的集合中获取信息并使用助手将其传递给模板。
这是我在 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}}
问题是它不会在呈现的页面中显示任何内容。
我确信这可能是我的错字或类似的东西,因为我对 meteor 很陌生,所以任何帮助将不胜感激。
您只是订阅了 dataForTableD1
,但您没有 return 数据到您的 day1p1
辅助函数中。您可能想使用 collection.findOne([selector], [options])
到 return 匹配选择器的文档。
请试试这个:
Template.timetable.helpers({
'day1p1': function() {
Meteor.subscribe('dataForTableD1');
return Day1.findOne(); // add here your selector and options
}
});