【问题标题】:Publishing custom Meteor.user() fields发布自定义 Meteor.user() 字段
【发布时间】:2013-10-25 01:31:29
【问题描述】:

我知道这个问题已经被问过很多次了,但是我很难发布这个信息。

在 Accounts.onCreateUser 中,我添加了一个类似这样的字段

{
 ...
 user['info'] = { email: options.email, is_admin: false};
}

我发布此信息;

Meteor.publish('user', function() {
    return Meteor.users.find({}, { fields: { info: 1} });
}

Meteor.subscribe('user');

在调试后发布查询返回正确的信息,但当我尝试访问 Meteor.user() 时从未将这些信息提供给客户端。我是否必须做其他事情才能允许 Meteor.user() 访问信息?

有什么建议吗?

【问题讨论】:

    标签: meteor


    【解决方案1】:

    您需要使用 null 来发布给单个用户。

    Meteor.publish(null, function() {
      return Meteor.users.find({_id: this.userId}, {fields: {info: 1}});
    });
    

    【讨论】:

    猜你喜欢
    • 2018-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多