這可能比我發出聲音更簡單。流星:在新創建的用戶上插入文檔
我允許我的用戶在登錄時創建自己的個人檔案。這是存儲在MyProfile = new Meteor.Collection('myprofile');
中的文檔。該原則與LinkedIn ...完全相同,您只需填寫個人資料表單和所做的任何編輯即可更新該文檔。
在文檔中會有諸如'summary''newsInterest'之類的字段,還有'owner'是用戶Id。
1)如何將文檔插入MyProfile集合,其'owner'字段是StartUp上新創建用戶的userId?
這是這樣的,這個文件的數據,這些字段的值將被傳遞到myprofile頁面。最初返回的值將是空白的,但隨着用戶鍵入,在鍵入時,myprofile文檔將被更新。
在客戶端上創建用戶如下。現在很好。
2)另外,如果用戶在服務器上創建了用戶,請提供任何鏈接。我調用了一個方法將以下內容作爲對象插入到Meteor.users.insert(object);
中,但這不起作用。
Template.join.events({
'submit #join-form': function(e,t){
e.preventDefault();
Accounts.createUser({
username: t.find('#join-username').value,
password: t.find('#join-password').value,
email: t.find('#join-email').value,
profile:{
fullname: t.find('#join-fullname').value,
summary: [],
newsInterest: [],
otherstuff: []
}
});
Router.go('myprofile');
}
});
我建議將Router.go('myprofile')添加到createUSer回調中,這樣如果出於某種原因createUser錯誤,它將不會嘗試更改頁面,並且可以向用戶顯示錯誤。看到我的代碼如下。 – 2014-10-22 10:46:21