【发布时间】:2016-03-14 16:54:32
【问题描述】:
我有一个Person,我希望在某人更改其firstName 或lastName 字段时自动创建一个fullName 字段和值。
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
我做错了什么?
【问题讨论】:
标签: meteor meteor-autoform meteor-collection2 simple-schema