【发布时间】:2019-12-09 00:10:37
【问题描述】:
我有一个数组,其中包含具有不同键值的对象。我想验证每个对象键。例如,age 字段只能获取 Equal 和 Not equal 运算符值。所以每个键的“op”键是不同的。例如,名称应与包含运算符一起使用。
[
{ age:21, op: "Equal" },
{ name:21, op: "Contains" },
{ date: 1564577662198, op: "Not equal" }
]
我已经写了一个架构,
{
"title": "ValidatorSchema",
"type": "array",
"items": {
"type": "object",
"properties": {
"age":{
"type": "number"
},
"operator" : {
"type" : "string",
"enum" : ["Equal" , "Not equal"]
},
"name":{
"type": "string"
},
"operator" : {
"type" : "string",
"enum" : ["Contains"]
}
}
}
}
但我无法将每个键与操作员联系起来。我该怎么做?
【问题讨论】: