0

Meteor Presence を使用すると、オンラインのユーザーの userId を返すことができます。ユーザー オブジェクトを取得する方法を確認したいと思います。

Meteor.publish('userPresence', function() {
  return Meteor.presences.find({}, {fields: {state: true, userId: true}});
});

ご覧のとおり、コレクションを公開し、サブスクライブしています。

Meteor.subscribe('userPresence');

すべてのオンライン ユーザーを取得するための各ブロックを含むビューがあります。

<template name="presenceList">
   <h1>{{onlineCount}}</h1>
   {{#each onlineUsers}}
      {{> presenceSingle}}
   {{/each}}
</template>

また、これはヘルパーを含むファイルです。

Template.presenceList.helpers({
    onlineUsers: function() {
    return Meteor.presences.find();
   },
   onlineCount: function() {
    return Meteor.presences.find().count();
   }
});

私の最大の苦労は、シングル ユーザー テンプレートでユーザー名を返すことです。

どんな助けでも素晴らしいでしょう、ありがとう。

4

2 に答える 2

0

Meteor.presences.find() から返されたドキュメントにユーザーの ID がありますか? Mongo から個々のユーザー オブジェクトを取得するクエリを実行しないのはなぜですか

Meteor.users.findOne({_id: theIDFromDoc});
于 2013-05-15T14:47:12.027 に答える