我是一个流星新手,我正在关注流星指南中的这个链接,向 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);
}
});
现在在服务器端用这个传递的信息写了方法来做 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 控制台上,我期待个人信息作为顶级字段,但没有,
在服务器端,日志是
I20160528-11:04:27.725(5.5)?更新后[object Object]
我似乎无法找出这里有什么问题?
感谢您阅读我的问题
更新:添加了重现此问题的步骤