本人新手,对js了解不深,js拼接对象里面含数组json字符串不知道怎么搞了,求大神指导
数组代码
var crulearr=[]
for(var ccode of this.newDB){
if(ccode.id == this.ipboxid){
crulearr.push('{"rules":[{"field":"ParentID","op":"equal","value":"'+this.ipboxid+'","type":"int"},{"field":"CarbinCode","op":"equal","value":"'+this.cabincodearr+'","type":"string"}],"op":"and"}')
}
else{
crulearr.push('{"rules":[{"field":"ParentID","op":"equal","value":"'+ccode.id+'","type":"int"},{"field":"CarbinCode","op":"equal","value":"'+ccode.cabincodes+'","type":"string"}],"op":"and"}')
}
}
console.log('row202:'+ JSON.stringify(crulearr))
数组数据如下:
拼json数据代码
var rules='{"groups":'+ JSON.stringify(crulearr) +',"op":"and"}'
this.prule=JSON.parse(rules)
console.log('row222:'+ JSON.stringify(this.prule) )
获取到的数据如下:
想要实现的数据格式: