【发布时间】:2015-05-11 23:53:18
【问题描述】:
@DavidWeldon 我尝试了您的代码 (Meteor observe changes added callback on server fires on all item),非常好,谢谢!
但是我想听听您的建议:我将它用于桌面通知:当我收到一个通知时,有一个控制台日志(好的),但是当我收到另一个通知(总数:2)时,有两个控制台日志(我只想要一个控制台日志,因为只有 +1 通知)
这是我的代码:
if (Notification.permission !== "granted")
Notification.requestPermission();
var query = Notifications.find({userId: Meteor.userId(), read: false});
(function() {
var initializing = true;
query.observeChanges({
added: function(id, notification) {
if (!initializing) {
console.log(notification);
}
}
});
initializing = false;
})();
感谢您的帮助! :)
【问题讨论】:
标签: meteor