用户集合的自定义字段发布无法正常工作

时间:2015-08-31 13:19:49

标签: meteor

我刚刚在默认用户表中添加了一个自定义字段。我们确实发布了特定字段并订阅了。当我们尝试访问帐户方法中的特定字段值时,#34; Accounts.onLogin"它在初始登录时具有价值,但在反应性刷新时会丢失。

if (Meteor.isServer) { 
  Meteor.publish("users",function(){
     return Meteor.users.find({_id:this.userId},{fields:{"customField":1}}); // Publish the user with custom fields
  });
}

if (Meteor.isClient) {
   Meteor.subscribe("users");
   Accounts.onLogin(function(){
     alert(Meteor.user().customField + ' Comes '); // it has value on initial login but it lost on reactive refresh.
   });
}

1 个答案:

答案 0 :(得分:0)

我认为您只能在Meteor.users中扩展profile ..请参阅此讨论了解更多信息:https://forums.meteor.com/t/how-to-add-new-field-on-meteor-users/1065/2