我有一个Person
并且我希望在一个人更改其或字段fullName
时自动创建一个字段和值。firstName
lastName
People.attachSchema(new SimpleSchema({
firstName: {
type: String,
optional: false,
label: 'First Name'
},
lastName: {
type: String,
optional: false,
label: 'Last Name'
},
fullName: {
type: String,
optional: false,
label: 'Full Name',
autoValue: function() {
var firstName = this.field("firstName");
var lastName = this.field("lastName");
if(firstName.isSet || lastName.isSet){
return firstName.value + " " + lastName.value;
} else {
this.unset();
}
}
}
}));
如果我这样做
People.update("ZqvBYDmrkMGgueihX", {$set: {firstName: "Bill"}})
fullName
设置为Bill undefined
我究竟做错了什么?