@DavidWeldon我尝试了你的代码(Meteor observe changes added callback on server fires on all item),非常感谢你!
但是我想建议你:我用它来进行桌面通知:当我收到一个通知时,有一个控制台日志(确定),但当我收到另一个通知(总计:2)时,有两个控制台log(我只想要一个控制台日志,因为只有+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;
})();
感谢您的帮助! :)
答案 0 :(得分:0)
你可以在那里使用另一面旗帜吗?
if (Notification.permission !== "granted")
Notification.requestPermission();
var query = Notifications.find({userId: Meteor.userId(), read: false});
(function() {
var initializing = true;
var firstNotif = true;
query.observeChanges({
added: function(id, notification) {
if (!initializing && firstNotif) {
firstNotif = false;
console.log(notification);
}
}
});
initializing = false;
})();