我有下面的 JSON,需要遍历“规则”对象。我似乎永远无法正确调用它,以便能够访问的不仅仅是最后一条规则。
如果有人能指出我正确的方向,我将不胜感激
var rules = [{
"rule":[{
"fields":["CASE.PROSECUTED_FLAG","CASE.RESTITUTION_SIGNED"],
"conditions":["N","Y"],
"actions":"required",
"action_fields":["test1","test2"]
}],
"rule":[{
"fields":["CASE.PROSECUTED_FLAG","CASE.RESTITUTION_SIGNED"],
"conditions":["N","N"],
"actions": "required",
"action_fields": ["test3", "test4"]
}],
"rule":[{
"fields":["CASE.PROSECUTED_FLAG"],
"conditions":["Y"],
"actions": "required",
"action_fields": ["test5"]
}]
}];
function rulesControl() {
alert(rules.length);
for (var rule in rules) {
var xfields = rules[rule].rule.fields;
var conditions = rules[rule].rule.conditions;
var actions = rules[rule].rule.actions;
var action_fields = rules[rule].rule.action_fields;
//test the fields (if success, mark them, else clear them)
if (validateRule(xfields, conditions)) {
rulesAction(actions, action_fields);
} else {
ruleActionMakeClear(action_fields);
}
}
}