【发布时间】:2020-06-15 20:39:05
【问题描述】:
我有一个包含对象数组的 JSON 模式。我希望这些对象内的一个字段依赖于数组外的属性。
我创建了以下架构:
{
type: "object",
properties: {
showNotes: {
title: "Add notes field",
type: "boolean",
},
choices: {
type: "array",
title: "Choices",
items: {
type: "object",
properties: {
itemName: {
type: "string",
title: "Item"
},
isRequired: {
type: "boolean",
title: "Required?",
default: false
},
note: {}
}
},
default: [
{
content: "Thing 1",
correct: false
}
]
}
},
dependencies: {
showNotes: {
oneOf: [
{
properties: {
showNotes: {
enum: [
false
]
}
}
},
{
properties: {
showNotes: {
enum: [
true
]
},
note: {
title: "Note",
type: "string"
}
}
}
]
}
}
}
我希望新字段 note 会更新 items/note 的字段,但它没有,而是在底部生成了一个新字段 note。可以在这里看到:
https://codepen.io/samfentr/pen/ZEQpeyg
我认为解决方案与添加 $ref 引用有关,但我无法解决。
【问题讨论】:
标签: jsonschema react-jsonschema-forms