2013-04-15 30 views
1

我們已經發布了基於列表ID的項目,我們使用myLists變量來過濾出列表ID,但是當我們嘗試添加新列表時,這個變量本質上沒有被動性,那麼新列表的項目不會自動發佈。Node.js如何重新發布數據。

Meteor.publish('subscription_items', function() { 
var userName = this.userId ? Meteor.users.find({ _id: this.userId }).fetch()[0].username : null; 

var myLists = []; 
var sharedListIDs = []; 
SharedLists.find({ shared_with: userName }).forEach(function (list) { 
    sharedListIDs.push(list.list_id); 
}); 

Lists.find({ $or: [{ owner: userName }, { _id: { $in: sharedListIDs } }] }).forEach(function (list) { 
    myLists.push(list._id); 
}); 

return Items.find({ list_id: { $in: Lists.find({ $or: [{ owner: userName }, { _id: { $in: sharedListIDs } }] }).fetch() } });. 

我們有什麼方法可以隨時發佈新鮮數據嗎?請幫我解決這個問題。任何幫助/建議將不勝感激。

回答

0

由於David Weldonthis answer中指出,對於我的類似問題,您要查找的是被動連接。通過使用包publish-with-relations,我想你想的發佈功能看起來是這樣的:

Meteor.publish('subscription_items', function() { 
    return Meteor.publishWithRelations({ 
    handle: this, 
    collection: Lists, 
    filter: {owner: this.userId}, 
    mappings: [{collection: SharedLists, key: 'list_id'}] 
    }); 
}); 

另外,作爲(髒)的解決方法,你可以調用

Meteor.subscribe('subscription_items'); 

無處不在,你需要收集將被重新發布。