如何部分更新meteor.users.profile? [英] How to partly update meteor.users.profile?

查看:72
本文介绍了如何部分更新meteor.users.profile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用模块account-ui启动了基于流星模板的min应用程序.

I have started a min app based on meteor boilerplate with the module accounts-ui.

创建了一个呼叫用户的集合,其元素之一是个人资料,它又具有一个名为名称"的元素,该元素获取登录名.

There is a collection created call users one of its elements is profile, this again has an element called "name" which gets the login name.

在此测试应用中,可以选择更新用户个人资料.更新数据来自表单提交.我在这里附加了事件监听器

With in this test app is an option to update a user profile. The data for the update comes from a Form submit. I have attached the event listener here

Template.profile.events({
  'submit form': function(event) {
    event.preventDefault();
    var data = SimpleForm.processForm(event.target);
    Meteor.users.update(Meteor.userId(), {$set: {profile: data}});
  }
});

因此,数据具有表格中的所有内容.登录名名称"不包含在表单中,因此也不包含在数据中.

So data has everything from the form. The loginname "name" is not contained in the form so also not in data.

在更新之前,我有users.profile.name->包含数据 更新后,我有了users.profile.*-> *等于表单中的所有内容,但名称"消失了.

before the update I have users.profile.name -> contains data after the update I have users.profile.* -> * equals everything from the form but "name" is gone.

最后:谁可以保留profile.name字段?最后,我希望在users.profile中包含PLUS中的所有名称".

Finally: who can I keep the profile.name field ? At the end I like to have in users.profile everthing from the from PLUS the "name" filed.

感谢您提供任何提示,当您阅读《流星》时,我并不陌生-并尝试了解事物之间的联系.

Thanks for any hint, as you read I am new to meteor - and try to understand how things link together.

迈克尔

推荐答案

您正在用数据对象替换整个现有的配置文件对象,因此之前的所有操作(包括名称键)都将被清除.

You're replacing the entire existing profile object with your data object, so anything that was there before, including the name key, is going to be wiped out.

如果名称是配置文件中唯一要保留的内容,只需使用其自己的密钥将其添加到数据对象中即可.这样,您放置在配置文件下的新对象将具有一个与旧对象相同的名称字段.

If name is the only thing in profile that you want to keep, just add it to your data object with its own key. That way the new object you place under profile will have a name field that is equivalent to the old one.

var data = SimpleForm.processForm(event.target);
data.name = Meteor.user().profile.name;
Meteor.users.update(Meteor.userId(), {$set: {profile: data}});

这篇关于如何部分更新meteor.users.profile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆