流星 - 观察自动运行功能内未运行
Meteor - observe not running inside autorun function
为什么当观察程序内的查询更改时不触发通知?当我将此代码放入帮助程序中时,它可以工作,但仅适用于该帮助程序模板。
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);
});
如果你使用 React,当你把它放在Template.someTemplate.onCreated
或componentWillMount
中时,你会得到什么日志?
Meteor.subscribe('theNotificationStatus');
Meteor.subscribe('theNotificationSubscriptions');
Tracker.autorun(function () {
var currentUserID = Meteor.userId();
var subscriptions = Subscriptions.find(
{userID: currentUserID},
{fields: {eventID: 1, category: 1}}
);
console.log('currently, there are', subscriptions.count(), 'subscriptions loaded');
var arrayEvents = [];
var arrayCategory =[];
subscriptions.forEach(function (subscription) {
arrayEvents.push(collection.eventID);
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({
eventID: { $in: arrayEvents },
category: { $in: arrayCategory },
createdBy: { $ne: currentUserID },
});
console.log('currently, there are', query.count(), 'status loaded');
var handle = query.observe({
added: function (status) {
console.log('new status', status);
},
});
});
相关文章:
- '.在'单击“不运行”功能
- 流星 - 观察自动运行功能内未运行
- on点击不运行功能??(可能是Javascript错误?)
- 加载检查单选按钮值并运行功能
- 如何在浏览器中完成图像大小调整后运行功能?(JS/JQuery)
- 在IE中下载文件时运行功能
- 应用程序关闭前的离子运行功能
- 离子选项卡在选择后运行功能
- 检查URL和运行功能
- Chrome扩展赢得't点击按钮运行功能
- 检查时间差是否小于45分钟,并运行功能-AngularJS
- 对输入更改和复选框更改运行功能
- 如何运行功能与参数点击
- 混淆自动运行功能
- 选择按钮运行功能
- 运行功能按钮点击作为创建者用户-谷歌电子表格
- 离子应用程序运行功能在第二次点击
- 谷歌图表-运行功能后绘制
- 具有对焦运行功能的按钮在'输入'
- Onchange选择运行功能