Javascript .findOne在Iron路由器路由的数据属性中工作,但.find不工作?
我正在写一个动态内容加载的应用程序。我正在使用Iron Router,如果可能的话,我的目标是避免会话。我写了下面的路线:Javascript .findOne在Iron路由器路由的数据属性中工作,但.find不工作?,javascript,meteor,iron-router,Javascript,Meteor,Iron Router,我正在写一个动态内容加载的应用程序。我正在使用Iron Router,如果可能的话,我的目标是避免会话。我写了下面的路线: Router.route('/:publisher',{ name: "publisher", action: function(){ this.render("Publisher") }, data: function(){ return Comics.findOne({publisher: this.params.publisher});
Router.route('/:publisher',{
name: "publisher",
action: function(){
this.render("Publisher")
},
data: function(){
return Comics.findOne({publisher: this.params.publisher});
}
});
就像它使用的一样,它是有效的。如果我将.findOne切换到.find,则不会加载任何内容,但不会出现错误。感谢您的帮助。谢谢
注意:我查看了这个链接,但遗憾的是它不是同一个问题:使用collection.find().fetch()
而不是collection.find()
collection.findOne()
大致相当于collection.find({},{limit:1}).fetch()[0]
解释
collection.find()
是一个光标,而collection.find().fetch()
是一个对象数组。尝试使用var finde=Comics.find({publisher:this.params.publisher}).fetch()
和console.log(finde)
这会导致多个数组,看起来它一直在循环,每次都向数组添加一个条目。然后将显示三个不同的数组,而不是附加原始数组。如果我记录Comics.find({publisher:This.params.publisher}).fetch(),则会产生三个数组。似乎它正在使用这些参数在集合上循环,并每次创建一个新数组,向其中添加新的查找。您是否在订阅完成之前呈现模板?我忘了添加waitOn。我真傻。谢谢