我发现我广泛使用用户配置文件。我希望能够做这样的事情:
Meteor.user().profile.some_setting = 'something';
Meteor.user().update();
更新用户个人资料最方便的方法是什么?
最佳答案
Meteor.user() 是一个文档,而不是一个游标。它实际上是 Meteor.users.findOne(this.userId)
的别名。
您可以通过方法调用(服务器)或直接在客户端上执行此操作。
方法调用方式:
//server code
Meteor.methods({
updateProfile : function(newProfile) {
if(this.userId)
Meteor.users.update(this.userId, {$set : { profile : newProfile }});
}
});
在客户端:
Meteor.call('updateProfile', myNewProfile);
我建议通过服务器方法来执行此操作,因为代码在更干净的环境中运行。
如果您想直接在客户端上执行此操作:
Meteor.users.update(Meteor.userId(), {$set : {profile : myNewProfile}});
(Meteor.userId()
是 Meteor.user()._id
的别名)
More infos on the doc!
关于Meteor.js - 更新用户个人资料最方便的方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26933335/