【问题标题】:#each blog post not displaying#每篇博文不显示
【发布时间】:2016-05-18 02:41:36
【问题描述】:

我有一个包含博客文章的集合,我正试图让它们显示在页面上。下面的代码没有列出所有的博客文章,我不知道为什么。据我所知,它正在出版。

路径:blog.html

{{#each Blog}}
    <p>{{details}}</p>
{{/each}}

路径:blog.js

Template.blog.onCreated(function() {
    var self = this;
    self.autorun(function(){
        var id = FlowRouter.getParam('id');
        self.subscribe('blog', id);
    });
});

路径:Blog mongoDB example

{
  "_id": "JvLqxFisXc3PLeqSh",
  "details": "Test three",
}

路径:publish.js

Meteor.publish('blog', function (id) {
  check(id, String);

  return Blog.find({}); 

});

【问题讨论】:

    标签: meteor


    【解决方案1】:

    我需要添加一个助手。

    Template.blog.helpers({
        blogPost: ()=> {
            return Blog.find({});
        }
    )}
    

    路径:blog.html

    {{#each blogPost}}
        <p>{{details}}</p>
    {{/each}}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-10
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多