流星 - 等到收集完全准备好

时间:2016-05-21 08:33:16

标签: mongodb meteor

我在集合服务中有此功能,它返回具有某些状态的服务。

_.extend(Services, {
    getServiceTypes: function () {
        return [
            { _id: '', serviceType: '' },
            { _id: 'Plumbing', serviceType: 'Plumbing' },
            { _id: 'Electrical', serviceType: 'Electrical' },
            { _id: 'HVAC', serviceType: 'HVAC' }
        ];
    },
    whereStatus: function (name) {
        let status = Statuses.findOne({ name: name });
        return this.find({ statusId: status._id });
    },
    whereServiceType: function (serviceType) {
        return Services.find({ serviceType: serviceType });
    }
});

whereServiceTypes()有效,但whereStatus()不起作用。这是因为变量状态是初始未定义的,然后它有一些值。我希望它等到状态具有Mongo集合返回的值,然后继续。

顺便说一句,我想把这些函数链接起来...... Services.whereStatus('Completed').whereServiceType('HVAC').fetch(),这可能吗?

0 个答案:

没有答案
相关问题