使用Javascript将对象(元素)向上移动一步
作者:互联网
我有几个像这样的对象:
我想将类型和值向上移动一步,以便它们将在字段旁边,然后删除数据.
部门转换为JSON时看起来像这样:
[
{"field" : "DEPARTMAN_NO",
"data" : { "type":"numeric" , "comparison":"eq" , "value":11 }
},
{"field" : "DEPARTMAN_ADI",
"data" : { "type":"string" , "value":"bir" }
}
]
我试过了:
departments = grid.filters.getFilterData();
i = {};
for(var i in department) {
department = i.data;
delete.department.data;
};
但它不起作用.
解决方法:
1)首先,循环部门,我们称之为部门的每个项目;
2)您想将department.data的属性移动到department,从另一个角度来看,您可以将department的属性移动到department.data并返回department.data,代码如下:
var departments = [{
"field": "DEPARTMAN_NO",
"data": {
"type": "numeric",
"comparison": "eq",
"value": 11
}
}, {
"field": "DEPARTMAN_ADI",
"data": {
"type": "string",
"value": "bir"
}
}],
department;
for (var i = 0, len = departments.length; i < len; i++) {
department = departments[i]; // department
for (var key in department) {
if (key !== 'data' && department.data) {
department.data[key] = department[key];
}
}
departments[i] = department.data || department; // if no department.data, no change
}
console.log(departments);
结果:
查看完整的演示http://jsfiddle.net/KVYE5/
标签:extjs4-1,javascript,javascript-objects,object,filter 来源: https://codeday.me/bug/20190823/1696271.html