0
爲什麼查詢在觀察內更改時不會觸發通知?當我把這段代碼放在幫助器中時,它可以工作,但只適用於該幫助器模板。流星 - 觀察未在自動運行功能內部運行
Tracker.autorun(function() {
Meteor.subscribe('theNotificationStatus');
Meteor.subscribe('theNotificationSubscriptions');
var currentUserID = Meteor.userId();
var usersEventIds = Subscriptions.find({userID: currentUserID}, {"eventID": 1});
var userCategorys = Subscriptions.find({userID: currentUserID}, {"category": 1});
var arrayEvents = [];
var arrayCategory =[];
usersEventIds.forEach(function (collection) {
arrayEvents.push(collection.eventID);
});
userCategorys.forEach(function (collection) {
arrayCategory.push(collection.category);
});
//All of the status's the user should be notified for based on what eventID and categories he/she is subscribed to.
var query = Status.find({ $and: [ { eventID: { $in: arrayEvents } } , { category: { $in: arrayCategory } }, { createdBy: { $ne: currentUserID } } ] }, {sort: {date: -1} });
var handle = query.observe({
added: function (id, fields) {
sAlert.success('New Notifications', {timeout: '6000'});
},
});
// After five seconds, stop keeping the count.
setTimeout(function() {handle.stop();}, 5000);
});
不應該是'Subscriptions.find({userID:currentUserID},{fields:{「eventID」:1}});'? – Guig
似乎沒有區別。仍然卡住! – user3541209