我使用以下领域SimpleSchema,autoValue用于更新不设置给定值
"fileNo": {
type: String,
label: "File No.",
autoValue: function() {
console.log('this', this);
console.log('typeof this.value.length ', typeof this.value.length);
console.log('this.value.length ', this.value.length, this.value.length === 0, this.value.length == 0);
console.log('this.value ', this.value, typeof this.value);
console.log('this.operator ', this.operator);
console.log('this.isSet ', this.isSet);
if (this.isSet && 0 === this.value.length) {
console.log('if part ran.');
return "-";
} else {
console.log('else part ran.');
}
},
optional:true
},
我使用autoform
到update
的字段。问题是当我使用空字符串(即保持文本框为空)更新字段时,值-
未按照上面SimpleSchema代码中的字段定义进行设置。
我得到的日志如下,
clients.js:79 this {isSet: true, value: "", operator: "$unset", unset: ƒ, field: ƒ, …}
clients.js:80 typeof this.value.length number
clients.js:81 this.value.length 0 true true
clients.js:82 this.value string
clients.js:83 this.operator $unset
clients.js:84 this.isSet true
clients.js:86 if part ran.
clients.js:79 this {isSet: true, value: "-", operator: "$unset", unset: ƒ, field: ƒ, …}
clients.js:80 typeof this.value.length number
clients.js:81 this.value.length 1 false false
clients.js:82 this.value - string
clients.js:83 this.operator $unset
clients.js:84 this.isSet true
clients.js:89 else part ran.
和我收集的文档没有场fileNo
。
我错过了什么?我要的全部是当fileNo
的值为empty/undefined
的值必须设置为-
(连字符)。在文档它必须看起来像fileNo : "-"
究竟是什么你试图达到? – Styx
@Styx:用粗体修改最后一行。提前致谢。 –
也许,'defaultValue'是你需要的吗? – Styx