【问题标题】:Meteor publish ALL Users does not seem to work (or even get called?)流星发布所有用户似乎不起作用(甚至被调用?)
【发布时间】:2015-12-11 22:06:07
【问题描述】:

我在 server/publications.js 中有以下内容...

Meteor.publish("users", function(){
  return Meteor.users.find({}, {fields: {profile: 1}});
});

...在我的铁路由路由...

Router.route('/', function() {
  this.layout('ConfLayout');
  this.render('UserList', {
    waitOn: function () {
      return Meteor.subscribe("users");
    },
    data: function () {
      return {
        users: function () {
          return Meteor.users.find();
        }
      };
    }
  });
});

...然后在我的模板中....

<template name="UserList">
  <h1>Users</h1>
  <ul>
    {{#each users}}
      <li>
        {{#linkTo route='user.show'}}
          <div>
            {{profile.lastName}}, {{profile.firstName}} 
          </div>
        {{/linkTo}}
      </li>
    {{/each}}
  </ul>
</template>

...除了客户端上唯一的用户是当前登录的用户之外,它有点工作。我正在尝试为管理员获取所有用户的列表(暂时不要担心管理员部分)。

同样奇怪的是,我在发布函数中添加了一个 console.log 语句,它永远不会被记录。但是,同一文件中的所有其他出版物似乎都可以正常工作。此外,如果我启用自动发布,那么所有用户都会按预期显示。

我在这里错过了什么?根据我能找到的所有内容,发布特定字段似乎应该适用于在客户端显示所有用户,但似乎 Meteor 似乎完全忽略了 Meteor.users 上的任何出版物。我正在使用 Meteor 1.1.0.3。

任何想法或帮助表示赞赏!

TIA

【问题讨论】:

    标签: meteor iron-router


    【解决方案1】:

    好的...不完全确定为什么,但我怀疑我可能在某处或某处遗漏了“this”,但如果我将路线更改为不使用函数作为第二个参数并传递选项然后离开其他一切都完全相同,它的工作原理......

    Router.route('/', {
        waitOn: function () {
          return Meteor.subscribe('users');
        },
        data: function () {
          return {
            users: function () {
              return Meteor.users.find();
            }
          };
        },
        template: 'UserList',
        layoutTemplate: 'ConfLayout'  
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-26
      • 1970-01-01
      • 2018-12-18
      • 2018-12-26
      • 2015-09-02
      • 1970-01-01
      相关资源
      最近更新 更多