2015-04-02 63 views
4

我一直在研究這個年齡,無法找到一個清晰的解釋。我的流星應用程序安裝了用戶帳戶,登錄/登出都可以正常工作。不過,我想爲我的用戶添加一些可選字段,例如年齡,性別等。我該如何去做這件事?請注意,我對流星很陌生,所以請明確。如何在Meteor中擴展用戶模型?

+1

可能重複的例子:([MeteorJS用戶收集如何公開新的領域] http://stackoverflow.com/questions/29383464/meteorjs-users-collection-如何對暴露出新場)。 – 2015-04-02 21:43:29

回答

3

要更多的字段添加到由useraccounts包提供的用戶登記表,請參見官方Guide

Form Fields Configuration節假設您要添加一個gender現場登記表格,你可以做這樣的事情

AccountsTemplates.addField({ 
    _id: "gender", 
    type: "select", 
    displayName: "Gender", 
    select: [ 
    { 
     text: "Male", 
     value: "male", 
    }, 
    { 
     text: "Female", 
     value: "female", 
    }, 
    ], 
}); 
2

您正在查找的文檔是Meteor.users集合。它在「完整API」下面http://docs.meteor.com,這可能解釋了爲什麼你錯過了它。

用戶文檔可以包含任何要存儲的關於用戶的數據。流星專門處理以下領域:

  • 用戶名:一個唯一的標識用戶的字符串。
  • 電子郵件:[...]
  • createdAt:創建用戶文檔的日期。
  • profile:用戶可以使用任何數據創建和更新的對象。除非您對Meteor.users集合有拒絕規則,否則不要在配置文件中存儲任何您不希望用戶編輯的內容。

[...]

默認情況下,當前用戶的用戶名,電子郵件和個人資料發佈到客戶端。您可以發佈更多的領域與當前用戶:

// server 
Meteor.publish("userData", function() { 
    if (this.userId) { 
    return Meteor.users.find({_id: this.userId}, 
          {fields: {'other': 1, 'things': 1}}); 
    } else { 
    this.ready(); 
    } 
}); 

// client 
Meteor.subscribe("userData"); 
+1

我認爲在這種情況下使用'null'發佈者會更好。請參閱上面的鏈接問題。 – 2015-04-02 21:43:54