Meteor不在html中显示集合中的信息(Meteor not displaying information from collection in html)

编程入门 行业动态 更新时间:2024-10-27 22:33:01
Meteor不在html中显示集合中的信息(Meteor not displaying information from collection in html)

我试图从流星中的集合中获取信息,并使用帮助程序将其传递给模板。

这是我在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 } });

更多推荐

本文发布于:2023-07-19 20:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1186780.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:信息   html   Meteor   collection   information

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!