我遇到过这样的情况:使用 Angular-meteor 的 Meteor 应用程序的页面(ui-router 状态)上很少有用户。我想做一个toast 每次用户执行操作时都会向所有用户显示,这是集合的更新。
我想为此我应该在集合更新时从服务器触发 toast,但由于它是 CSS 和客户端的事情,我不知道如何做到这一点。
有没有一种方法可以在集合上实现一些监听器,并通过 toast 通知当前处于特定状态(页面)的所有用户何时更新它?
最佳答案
您必须创建一个通知集合,为每个用户的每个操作插入一个通知。您还需要一个仅订阅当前用户通知的通知发布/订阅。然后,在您的模板助手中:
notifications() {
var notification = Notifications.findOne();
if( notification ) {
// Execute a modal popup or something - make sure to pass the current value.
// Call a meteor method to remove the notification.
}
}
关于javascript - Meteor 中的服务器端触发 toast,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35450422/