【问题标题】:Meteor not displaying information from collection in html流星不在html中显示集合中的信息
【发布时间】:2016-02-27 08:03:42
【问题描述】:

我正在尝试从流星中的集合中获取信息并使用帮助器将其传递给模板。

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

问题是它不会在呈现的页面中显示任何内容。

我确信这可能是我的错字或类似的东西,因为我对流星很陌生,所以任何帮助都将不胜感激。

【问题讨论】:

    标签: javascript html meteor meteor-blaze meteor-helper


    【解决方案1】:

    您只是订阅了dataForTableD1,但您没有在day1p1 辅助函数中返回数据。您可能希望使用 collection.findOne([selector], [options]) 返回与选择器匹配的文档。

    请试试这个:

    Template.timetable.helpers({
        'day1p1': function() {
            Meteor.subscribe('dataForTableD1');
            return Day1.findOne(); // add here your selector and options
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多