2016-04-28 73 views
1

新文檔的問題是在服務器上的下一個代碼:Meteor.publish服務器上不顯示在客戶端

Meteor.publish(null , function() { 
    let events = []; 
    Groups.find({participants: this.userId}).forEach(function(item) { 
     events.push(item.latestEvent); 
    }); 
    return Events.find({_id: {$in: events}}); 
}); 

不提供可能性,看看客戶端上的新文件> Events.find().fetch() 無需重新加載頁面。

兩個集合都在lib文件夾:

Groups = new Mongo.Collection('groups'); 
Events = new Mongo.Collection('events'); 

我敢肯定的問題是數據的反應源,但仍無法修復它。

謝謝你的幫助!

回答

0

是的,你是對的:只有事件收集是被動的。有簡單的方法,通過使用publish-composite包來解決這個問題:

Meteor.publishComposite(null, { 
    find(){ 
     return Groups.find({participants: this.userId}); 
    }, 
    children: [{ 
     find(group){ 
     return Events.find({_id: {$in: group.latestEvent}}); 
     } 
    }] 
}); 

但這種方法有一個缺點:組文件發佈爲好。所以,你可能應該排除一些領域。

相關問題