【问题标题】:Meteor send to active users流星发送给活跃用户
【发布时间】:2014-03-25 16:27:10
【问题描述】:

我从写一个 meteorjs 网页开始。我从排行榜示例开始。这很好用。我添加了一些新功能。我添加了一个 jquery 通知脚本。 (通知http://ned.im/noty/

当我给一个人五分时,使用此代码激活 Noty 插件

var n = noty({text: txt,timeout: 2000});
......
Template.leaderboard.events({
    'click input.inc': function () {
      Players.update(Session.get("selected_player"), {$inc: {score: 5}});
      notje("Er heeft iemand een score gegeven");
      Method.call("callHouse");
    },

通知只会显示给我的浏览器,不会显示给其他用户。我如何向所有活动用户使用通知。 用户 -> 服务器 -> 所有用户

希望你能帮我解决这个问题

【问题讨论】:

  • 在服务器端Meteor.users.find({}) 会给你所有登录的用户。

标签: javascript jquery node.js meteor meteorite


【解决方案1】:

您必须创建一个通知集合(客户端和服务器):

notifications = new Meteor.Collection("notifications");

然后将您的消息插入其中并使用观察句柄显示它。确保添加特定于用户的内容,以便您可以使用较小的用户子集。并确定何时使用并将它们标记为准备就绪,以便它们不再发布并且用户不会继续接收它们。

然后你可以在你的客户端做这样的事情:

Meteor.startup(function() {
    notifications.find().observe({
        added: function(doc) {
            //Message can be contained in doc.txt

            //Not sure if this bit is right, but basically trigger the notification:
            n = noty({text: doc.txt,timeout: 2000});
        }
    });
});

希望这能让您大致了解如何操作。

【讨论】:

  • 哇,谢谢您的回复。如何激活收藏:像这样...notifications. added(text("Er heeft iemand een score gegeven"));
  • 你想让它做什么?但是,如果您仍然使用观察者,您可以编写自己的 text 方法来执行此操作。
猜你喜欢
  • 1970-01-01
  • 2013-11-12
  • 2018-08-14
  • 1970-01-01
  • 2013-02-27
  • 1970-01-01
  • 2012-10-02
  • 1970-01-01
  • 2015-02-28
相关资源
最近更新 更多