流星发现不返回数据

Meteor find not returning data

我的 collection 是在 collections.js

中创建的
portfolioCategories = new Mongo.Collection('portfoliocategories');

然后在subscriptions.js

订阅
Meteor.subscribe('portfoliocategories');

并发表于publications.js

Meteor.publish('portfoliocategories',function(){
    return portfolioCategories.find();
});

如果我使用 db.portfoliocategories.find() 从服务器查询 Mongo 我会得到

{ "_id" : "W9AeauCpMgPw2j5hf", "title" : "Commercial Design", "slug" : "commercial-design", "image" : "https://url/9c3ba46d-c09a-4a7d-ac40-5752fc24ad2c.jpg" }

但是,从客户端和 ironrouter 都找不到 return 任何东西。例如,如果我在控制台中输入:

portfolioCategories.find({'_id':'W9AeauCpMgPw2j5hf'});

我将得到一个 LocalCollection.Cursor 具有未定义的键值:

_selectorId: undefined

_transform: null

collection: LocalCollection

fields: undefined

limit: undefined

如果我尝试 return 作为数据,iron-router 也会发生同样的事情。但是,如果我使用 findOne,我会得到文档。

portfolioCategories.findOne({'_id':'W9AeauCpMgPw2j5hf'})

Object { "_id" : "W9AeauCpMgPw2j5hf", "title" : "Commercial Design", "slug" : "commercial-design", "image" : "https://url/9c3ba46d-c09a-4a7d-ac40-5752fc24ad2c.jpg" }

我的问题是我需要 return 所有具有相同标题的项目。 因此,findOne() 不是一个合适的解决方案。

我错过了什么?

混淆的产生是因为iron-router的数据对象不同。我试图从 iron-router 做的是

waitOn:function(){

    return [Meteor.subscribe('projectsportfolio'),Meteor.subscribe('portfoliocategories')];

}
data:function(){
    currentSlug = this.params.category;
    currentCategory = projectsPortfolio.find({slug:currentSlug});
    if(typeof currentCategory != 'undefined'){
        return currentCategory
    }
}

但这只是 returns @David Weldon 解释的游标。 解决方法是:

data:function(){
    currentSlug = this.params.category;
    currentCategory = projectsPortfolio.find({slug:currentSlug}).fetch();
    if(typeof currentCategory != 'undefined'){
        return currentCategory
    }
}

currentCategory 现在将是一个对象数组,我现在可以在我的模板中循环访问这些对象

{{#each currentCategory}}
    {{keyvalue}}
{{/each}}