所以说我有一个这样的简单模式:
const SomeItem = new Mongo.Collection("someitems");
Schemas.SomeItem = new SimpleSchema({
_id: {
type: String,
autoValue: function() { return Random.id(); },
},
normalvalue: String,
hiddenvalue: String,
}, {
/* Options for cleaning up the input before insert/update */
clean: {
filter: true,
autoConvert: true,
removeEmptyStrings: true,
trimStrings: true,
getAutoValues: true,
removeNullsFromArrays: true,
},
});
SomeItem.attachSchema(Schemas.SomeItem);
const SomeItemList = new Mongo.Collection("someitemlist");
Schemas.SomeItemList = new SimpleSchema({
_id: {
type: String,
autoValue: function() { return Random.id(); },
label: false,
},
title: String,
SomeItems: {
type: Array,
optional: true,
},
"SomeItems.$": Schemas.SomeItem,
unhidablevalue: String,
}, {
/* Options for cleaning up the input before insert/update */
clean: {
filter: true,
autoConvert: false,
removeEmptyStrings: true,
trimStrings: true,
getAutoValues: true,
removeNullsFromArrays: true,
},
});
SomeItemList.attachSchema(Schemas.SomeItemList);
然后我有一个这样的表格:
const SomeItemListForm = (props) =>
<AutoForm
// pre-populate model with auto values
model={ Schemas.SomeItemList.clean({}) }
schema={ Schemas.SomeItemList }
>
<AutoFields
omitFields={ [
"_id",
"hiddenvalue",
"unhidablevalue", // This doesn't work
"SomeItems.unhidablevalue", // This also doesn't work
"SomeItems.$._id", // Also doesn't hide the id
"SomeItems.$.unhidablevalue", // Also not working
] }
/>
<ErrorsField />
<SubmitField />
</AutoForm>;
因此,问题在于,尽管试图以各种方式省略目标,但_id
字段和unhidablevalue
仍显示在表单的子模式(SomeItems
)部分中。检查元素的字段名称类似于SomeItems.0._id
。 omitFields
是否完全适用于子计划,我应该如何忽略这些字段?我应该放弃这种方法,尝试其他更详细的解决方案吗?