【发布时间】:2015-01-12 07:14:40
【问题描述】:
我正在使用 angularjs 和流星实现一个通知系统。
在我的发布代码中,
我有这样的事情:
var retVal = Notifications.find({recipient: userId});
var handle = retVal.observeChanges({
//when a new notification is added
added: function (doc, idx) {
count++;
if (!initializing){
console.log("A record was added");
self.changed("counts", userId, {count: count});
}
},
removed: function (doc, idx) {
count--;
self.changed("counts", userId, {count: count});
}
});
最后我返回了 retVal。 在我的控制器中,我订阅了该出版物。 代码看起来很好,每当添加新文档时服务器都会触发添加的功能。但是,当添加新文档时,如何通知客户端(例如在我的控制器中触发一个函数)?添加的功能只在服务器触发。
【问题讨论】: