.findOne在Iron Router Route的数据属性中工作,但是.find没有?

时间:2015-02-01 23:58:44

标签: javascript meteor iron-router

我正在编写一个包含动态内容加载的应用。我正在使用Iron Router,我的目标是尽可能避免Sessions。我在下面写了以下路线:

Router.route('/:publisher',{
  name: "publisher",
  action: function(){
    this.render("Publisher")
  },
  data: function(){
    return Comics.findOne({publisher: this.params.publisher});
  }
});

哪个有用,因为它使用.findOne。如果我将.findOne切换为.find,则没有任何加载,但没有错误。任何帮助表示赞赏。感谢

注意:我查看了此链接,但遗憾的是不一样的问题:findOne works but not get all/find

1 个答案:

答案 0 :(得分:2)

使用collection.find().fetch()代替collection.find()

collection.findOne()大约相当于collection.find({},{limit: 1}).fetch()[0]

<强>解释

collection.find()是一个游标,而collection.find().fetch()是一个对象数组。