Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript .findOne在Iron路由器路由的数据属性中工作,但.find不工作?_Javascript_Meteor_Iron Router - Fatal编程技术网

Javascript .findOne在Iron路由器路由的数据属性中工作,但.find不工作?

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});

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

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。我真傻。谢谢