我正在开发 Meteor 应用程序。有时,服务器会使用外部数据库中的数据更新当前用户。发生这种情况时,我想在客户端打开的应用程序的任何页面上显示警报。我知道 Meteor.user 会在客户端上自动更新,但我不知道如何以及在哪里让应用程序监视用户的更改并对它们使用react。对此有什么想法吗?
用户更新是通过向服务器发送消息来触发的:
Router.map(function() {
this.route('/reload_user', {where: 'server'}).post(function() {
var data = this.request.body;
var user = Meteor.users.findOne({ "profile.id": data.id });
var data = Account.getAccountInfo(apiKey, secretKey);
Meteor.users.update(user._id, {
$set: {
"profile.paywall": data.paywall,
}
});
this.response.end();
});
最佳答案
在服务器端,您希望公开用户集合的发布。在客户端上,您希望自动订阅该出版物并处理更改的事件:
Meteor.autosubscribe(function() {
Meteor.users.find().observe({
changed: function(item) {
alert(item);
}
});
});
关于javascript - Meteor 用户更新时显示提醒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31274391/