2015-04-03 21 views
0

我有一篇文章模型,我已經發布並且工作正常。不過,我已經通過simpleSchemas插件添加了以下字段:如何將郵政領域與用戶電子郵件相關聯? [METEOR]

userEmail: { 
    type: String, 
    autoValue: function() { 
    if (this.isInsert) { 
     return Meteor.user().email; 
    } else if (this.isUpsert) { 
     return {$setOnInsert: Meteor.user().email}; 
    } else { 
     this.unset(); 
    } 
    } 
} 

當我有這個啓用後,提交表單不工作,但沒有提出任何錯誤。我可能錯誤地呼籲Meteor.user().email?如何將userEmail字段與創建該帖子的用戶的電子郵件相關聯?

回答

1

正確的語法是。

Meteor.user().emails[0].address 
+0

啊,謝謝你! – zenben1126 2015-04-05 13:13:21

-1

默認的Meteor.users集合將電子郵件存儲在數組中(以支持多個電子郵件)。像return Meteor.user().emails[0].address應該工作。

+0

喜@Curtis正確的大成是'Meteor.user()。電子郵件[0] .address'不'Meteor.user()。電子郵件[0]'你缺少'emails'和'。地址' – Ethaan 2015-04-03 17:35:29

相關問題