【发布时间】:2020-03-04 11:44:28
【问题描述】:
我正在尝试生成一个可以具有多个递归字段的表单。我使用了https://codepen.io/crickford/pen/ZmJqwd 这个演示(我没有使用任何自定义组件)。每当我使用 "$ref" 时,它都会忽略它。我正在使用 vue-json-schema-form。这是githubhttps://github.com/crickford/vue-json-schema-form的链接。 即使我使用 "$ref":"#" 它也不起作用。
我的 Json 模式是有效的。即使我在 codepen 中替换了以下架构,我也没有得到预期的结果,因为它通过在此链接中编辑 source 的 schema 属性给了我正确的输出@ 987654323@
我不知道我错在哪里!至少在 codepen 附加的模式代码中应该可以工作。 请指导我或与我分享工作演示小提琴。提前致谢。
这是我的架构:
{
"type": "object",
"title": "",
"properties": {
"Namespace": {
"type": "string",
"title": "Namespace ",
"attrs": {
"placeholder": "Namespace",
"title": "Please enter Namespace"
}
},
"Name": {
"type": "string",
"title": "Display Name : ",
"attrs": {
"placeholder": "Display Name",
"title": "Please enter Display name"
}
},
"SubSteps": {
"type": "array",
"title": "SubSteps",
"items": {
"type": "object",
"title": "Sub step",
"$ref": "#/definitions/SubSteps"
}
}
},
"definitions": {
"SubSteps": {
"type": "object",
"title": "SubStep item",
"properties": {
"Namespace": {
"type": "string",
"title": "Namespace ",
"attrs": {
"placeholder": "Namespace",
"title": "Please enter Namespace"
}
},
"Name": {
"type": "string",
"title": "Display Name : ",
"attrs": {
"placeholder": "Display Name",
"title": "Please enter Display name"
}
},
"SubSteps": {
"type": "array",
"title": "SubSteps",
"items": {
"type": "object",
"title": "Sub step",
"$ref": "#/definitions/SubSteps"
}
}
}
}
},
"required": [
"Name"
]
}
【问题讨论】:
-
使用 JSON Schema 生成表单不是标准化的。每个图书馆都会“做自己的事”(tm)。对于 vue-json-schema-form,代码库中没有提到
$ref,因此我只能假设它不受支持。 -
鉴于您在相关的 github 存储库上留下了问题,您可能希望在此处删除您的问题。就 JSON 架构验证而言,您的架构是正确的。
-
还有其他方法可以使用json-schema和refs OR json在vue js中生成动态表单吗?
-
当然,您可以编写自己的代码来执行此操作。或者您可以使用没有 vue 接口的备用库。这真的取决于你需要什么。
标签: vue.js jsonschema json-ref