我有一个json
数组,如下所示:
[{ "qbCondition": "OR"},{"fieldId": "ca.Primary_Diagnosis_Dt" ,"operator":"not_equal","fieldValue": "1991/11/17"},{"fieldId": "ca.Clinical_Stage","operator": "not_equal","fieldValue": "I"}]
我只想把这个数组放进去:
var rules_widgets = { condition: 'qbCondition', rules: [{ id: 'fieldId',operator: 'operator', value: 'fieldValue'},{id: 'fieldValue',operator: 'operator', value: 'fieldValue' },]};
我试过了:
$(data).each(function(idx, obj){
$(obj).each(function(key, value){
console.log(JSON.stringify(key) + ": " + JSON.stringify(value));
});
});
但我不知道如何动态设置这些值以创建上述json
答案 0 :(得分:0)
您可以执行this
之类的操作var x = [{ "qbCondition": "OR"},{"fieldId": "ca.Primary_Diagnosis_Dt" ,"operator":"not_equal","fieldValue": "1991/11/17"},{"fieldId": "ca.Clinical_Stage","operator": "not_equal","fieldValue": "I"}]
var rules = [];
for(var i=1; i<x.length; i++) {
rules.push({
id: x[i].fieldId,
operator: x[i].operator,
value: x[i].fieldValue
})
}
var rules_widgets = {
condition: x[0].qbCondition,
rules: rules
}