我有一个像这样的有效 JSON 对象:
{
"reasons": {
"options": [
{
"value": "",
"label": "Choose a reason",
"selected": true,
"requiresValidation": false
},
{
"value": "small",
"label": "Too little",
"selected": false,
"requiresValidation": false
},
{
"value": "big",
"label": "Too big",
"selected": false,
"requiresValidation": false
},
{
"value": "unsuitable",
"label": "I don't like it",
"selected": false,
"requiresValidation": true
},
{
"value": "other",
"label": "Other",
"selected": false,
"requiresValidation": true
}
]
}
}
我有一个变量,它存储一个unsuitable
可用选项的值(例如)options
。如何检索requiresValidation
存储在变量中的值的字段值,而不必遍历里面的所有对象值options
?
例如,如果 var 内容是other
我想访问requireValidation
其值为other
(即true
)的对象的字段。是否可以?谢谢你。