我有一个在Meteor应用程序中附加了SimpleSchema的MongoDB集合。在前端,我使用meteor-autoform包中的quickform来快速呈现表单。(https://github.com/Meteor-Community-Packages/meteor-autoform)
export const MyCollection = new Mongo.Collection('my-collection');
export const MySchema = new SimpleSchema({
name: {
type: String
},
isSuperDuper: {
type: Boolean,
optional: true
}
});
MyCollection.attachSchema(MySchema);
const exampleDoc = { name: 'Waka Waka' };
MyCollection.insert(exampleDoc);前端表单:
{{> quickForm collection="MyCollection" doc=myDoc id="updateMyDoc" type="update"}}quickform使用isSuperDuper布尔值加载我的exampleDoc,该布尔值的赋值为false。我在使用AutoForm.getFormValues('updateMyDoc')的客户端控制台上看到它,如果我检查mongo shell没有isSuperDuper密钥,正如预期的那样。当我保存quickForm时(没有做任何修改),文档就被分配了isSuperDuper: false。
在不自动将我的模式中的空布尔值转换为false值的情况下,是否可以使用quickform?
我曾尝试修改quickform设置autoConvert=false和removeEmptyStrings=false,但都无济于事。
谢谢你的帮助。
发布于 2020-06-07 07:52:51
我猜问题是你使用了默认的"checkbox“,它只有两种可能的状态(选中/未选中)。未选中将映射到false。
请参阅文档的这一部分:https://github.com/Meteor-Community-Packages/meteor-autoform#affieldinput
If you don't include a type attribute, the following logic is used to automatically select an appropriate type:
...
* Otherwise if the schema type is Boolean, the boolean-checkbox
type is used. You may want to specify a type of boolean-radios
or boolean-select instead. If you do so, use the trueLabel,
falseLabel, and nullLabel attributes to set the labels used
in the radio or select control.这听起来像是您可以指定单选或选择选项来允许null状态,这可能会为可选的布尔值产生更好的结果(本质上是给它第三个状态)。
https://stackoverflow.com/questions/62238262
复制相似问题