这可能比我发出声音更简单。流星:在新创建的用户上插入文档
我允许我的用户在登录时创建自己的个人档案。这是存储在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