这是非常简单的实现,但我的语法可能存在一些问题:
Template.userProfilePage.events({
'submit #profile-page': function(event, template) {
event.preventDefault();
var name = template.find('#fullName').value,
address = template.find('#address').value,
company = template.find('#company').value,
otherField = template.find('#other').value;
alert(name);
Meteor.users.update(
{ _id:Meteor.user()._id },
{
$set: {
"profile.name":name,
"profile.address":address,
"profile.company":company,
"profile.other":other
}
},
{ upsert: true },
{ multi: true }
);
return false;
}
});
模板包含普通的 html 页面。它总是抛出错误:
RangeError: Maximum call stack size exceeded.
最佳答案
如果您只更新一个用户,则不需要 multi: true
。也永远不需要更新;如果您正在与登录用户一起工作,则 users
集合中应该始终有他们的文档。尝试这样的事情:
Meteor.users.update(
Meteor.userId(),
{$set: {
"profile.name": name,
"profile.address": address,
"profile.company": company,
"profile.other": other
}
}
);
还要确保您的allow
和deny
规则允许您执行此更新。
附言我怀疑您的错误消息可能是因为您将 { multi: true }
作为 .update
的第四个参数。根据 docs ,语法是collection.update(selector, modifier, [options], [callback])
;所以如果你想同时使用 multi
和 upsert
,在第三个参数中将它们组合成一个对象:{ multi: true, upsert: true }
code>(您也可以只使用 collection.upsert
而不是 .update
)。您的错误可能是由于您发送对象 { multi: true }
作为第四个参数而不是 update
期望的回调函数引起的。
关于javascript - meteor :更新多个配置文件值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25672155/