我正在使用alpacajs库将我的json架构构建为不支持oneOf关键字的表单。
我有一个简单的要求,即如果存在一个字段,则应隐藏另一个字段。
有没有办法在不使用oneOf关键字的情况下使用json架构实现。
现在我使用dependencies
关键字来处理我的情况。
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Company Setup",
"description": "Company Wizard Setup",
"type": "object",
"properties": {
"name": {
"type": "string",
"title": "Company Name"
},
"alternate_names": {
"type": "array",
"title": "Alternate Name",
"items": {
"type": "string"
},
"maxItems": 5
}
},
"dependencies": {
"name": "alternate_names"
}
}
{
"options": {
"fields": {
"name": {
"dependencies": {
"alternate_names": "Value for empty Array?"
}
},
"alternate_names": {
...
}
}
}
}
为了清晰起见,这只是我的架构的精简版本,如果有人可以帮助我判断是否可以使用依赖项来删除字段,我将不胜感激。我可能只是使用javascript来获取这个,但我想使用模式处理这个,因为我也将使用相同的验证,infact模式更多地用作验证器而不是表单本身。
由于该字段都不是布尔值,因此我无法将值设置为true和false。
提前致谢。