我正在使用aldeed:autoform,aldeed:simple-schema,aldeed:collection2和mdg:validated-method用于对集合执行插入操作。SimpleSchema无效密钥“_id required”
这是自动窗体的tempalte:
<template name="Areas_agregar">
{{> Titulos_modulos title="Areas" subtitle="Agregar" cerrar=true}}
{{
#autoForm
collection=areasColecction
id="areas_agregar"
type="method"
meteormethod="areas.insert"
}}
{{> afQuickField name='nombre'}}
{{> afArrayField name='subareas'}}
<button type="submit">Save</button>
<button type="reset">Reset Form</button>
{{/autoForm}}
</template>
这是集合的模式:
Areas.schema = new SimpleSchema({
_id: {
type: String,
regEx: SimpleSchema.RegEx.Id
},
nombre: {
type: String,
label: 'Nombre'
},
subareas: {
type: [String],
label: 'Subareas'
}
});
这是插入方法:
const AREA_FIELDS_ONLY = Areas.simpleSchema().pick(['nombre', 'subareas', 'subareas.$']).validator({ clean: true, filter: false });
export const insert = new ValidatedMethod({
name: 'areas.insert',
validate: AREA_FIELDS_ONLY,
run({ nombre, subareas }) {
const area = {
nombre,
subareas
};
Areas.insert(area);
},
});
而我在Chrome的开发控制台中出现以下错误:
间为 “areas_agregar” 上下文SimpleSchema无效的键: 阵列[1] 0:对象 名: “_id” 类型: “必需的” 值:空 原:对象 长度:1 原型:Array [0]
就像错误显示,问我为_id字段的值,但我在插入更新,它没有任何意义。
任何想法可能会出错?
如果你使'_id''可选:true',那么你的插入将工作,流星会自动插入'_id' –
是的!这工作。但是为什么在'todos'示例项目中,'_id'字段中没有'_id optional:true'? –
该项目是否使用autoform? –