将顶级字段添加到Meteor.user文档中

时间:2016-05-28 06:01:01

标签: javascript meteor-accounts customizing

我是流星新手,我正在关注流星指南的this链接,为Meteor.user文档添加更多字段,

 Template.CustomDataForm.events({
        "click [data-action='Customer/insert']": function (event) {
            event.preventDefault();
            var name = $('[name=name]').val();
            var email = $('[name=email]').val();
            var phone = $('[name=phone]').val();
            var address = $('[name=address]').val();
            const personalInfo = {
                Name: name,
                Email: email,
                Phone: phone,
                Address: address,
            };
           // I want to add personalInfo as a top-level field onto the user document
            Meteor.call('updateInfo',personalInfo);
         }
    });

现在在服务器端写了Method,用这个传递的信息做了Meteor.user.update

 Meteor.methods({
           'updateInfo': function (newpersonalInfo) {
            console.log("Updating Info ..."+newpersonalInfo.Name+"  "+newpersonalInfo.Address+" "+Meteor.userId()) ;

            const proInfo = {
                Name: newpersonalInfo.Name,
                Email: newpersonalInfo.Email,
                Phone: newpersonalInfo.Phone,
                Address: newpersonalInfo.Address,
            };
            console.log("Updating for user "+Meteor.userId());
            Meteor.users.update(Meteor.userId(), {
                $set: {
                     personaInfo: proInfo
                }
            });
            console.log("After Updating"+Meteor.user());
        }
    });

以下是自定义数据的发布

Meteor.publish('Meteor.users.personalInfo', function ({ userIds }) {
  // Validate the arguments to be what we expect
  new SimpleSchema({
    userIds: { type: [String] }
  }).validate({ userIds });

  // Select only the users that match the array of IDs passed in
  const selector = {
    _id: { $in: userIds }
  };

  // Only return one field, `personalInfo`
  const options = {
    fields: { personalInfo: 1 }
  };

  return Meteor.users.find(selector, options);
});

以下是订阅

Template.profile.rendered = function () {
    Meteor.subscribe('Meteor.users.personalInfo',Meteor.userId());
    if (Meteor.user() && Meteor.user().personalInfo) {
        name = Meteor.user().profileInfo.Name;
        $('[id=profile-name]').val(name);
    }
}

但是在Javascript控制台上

Meteor.user()的输出;在Javascript控制台上,我期待个人信息作为一个顶级字段,但没有,

enter image description here

在服务器端,日志为

I20160528-11:04:27.725(5.5)?更新[对象]后

我似乎无法找出这里被破坏的东西?

感谢您阅读我的问题

更新:已添加Steps以重现此问题

0 个答案:

没有答案