.findOne 在 Iron Router Route 的数据属性中工作,但 .find 不能

.findOne works in data attribute of Iron Router Route but .find does not?

本文关键字:工作 find 不能 数据属性 Iron Router Route findOne      更新时间:2023-09-26

我正在编写一个具有动态内容加载的应用程序。我正在使用铁路由器,如果可能的话,我的目标是避免会话。我在下面写了以下路线:

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

这有效,因为它使用 .findOne。如果我将 .findOne 切换到 .find,则不会加载任何内容,但没有错误。任何帮助,不胜感激。谢谢

注意:我看了这个链接,但遗憾的是这不是同一个问题:findOne 有效,但不能全部获取/查找

使用 collection.find().fetch() 而不是 collection.find()

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

解释

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