我的架构:
{
type: "object",
required: [
"title",
"type",
],
definitions: {
typeSelectorDef: {
type: "string"
}
},
properties: {
title: {
type: "string",
title: "Title"
},
type: {
type: "string",
title: “Type",
enum: ["a1" ,"a2","a3"],
}
}
}
当我选择类型下拉列表时,我想在 typeSelectorDef 中添加属性。就是这样
definitions: {
typeSelectorDef: {
type: "string",
selectedIndex:"a2"
}
}
当 onchange 事件在表单中被触发时,我为在对象中添加属性做了定义黑客
const onChange = formData => {
let modifiedSchema = { …selectedSchema };
modifiedSchema.schema.definitions.TypeSelectorDef["selectedIndex"] = _.get(
formData,
“type",
“A1"
);
}
我怎样才能更干净地编写代码?