我想将下面的 json 格式转换为相应的 json 格式。我从 Rest 服务收到的 Json 不支持该设计。我厌倦了实现以下列表视图
JSON 格式(我从 Rest 服务接收)
{
"ActionHistory": [{
"id": "action",
"name": "Action History",
"children": [{
"childrenItem": {
"id": "action1",
"type": "fa fa-info",
"empId": "101",
"ActionDate": "on 18-Apr-2017 18:20:32",
"Action": "Submit",
"From": "Deb Raphaely",
"To": "Neena Kochlar",
"pic": "deb_avatar",
"Details": ""
}
}, {
"childrenItem": {
"id": "action2",
"type": "fa fa-info",
"empId": "101",
"ActionDate": "on 19-Apr-2017 18:20:32",
"Action": "Approve",
"From": "Neena Kochlar",
"To": "James",
"pic": "neena_avatar",
"Details": ""
}
}]
},
{
"id": "action",
"name": "Action History2",
"children": [{
"childrenItem": {
"id": "action1",
"type": "fa fa-info",
"empId": "101",
"ActionDate": "on 18-Apr-2017 18:20:32",
"Action": "Submit",
"From": "Deb Raphaely",
"To": "Neena Kochlar",
"pic": "deb_avatar",
"Details": ""
}
}, {
"childrenItem": {
"id": "action2",
"type": "fa fa-info",
"empId": "101",
"ActionDate": "on 19-Apr-2017 18:20:32",
"Action": "Approve",
"From": "Neena Kochlar",
"To": "James",
"pic": "neena_avatar",
"Details": ""
}
}]
}
]
}
我需要的 JSON 格式
{
"ActionHistory": [
{
"attr": {
"id": "action",
"name": "Action History"
},
"children": [{
"attr": {
"id": "action1",
"type": "fa fa-info",
"empId": "101",
"ActionDate": "on 18-Apr-2017 18:20:32",
"Action": "Submit",
"From": "Deb Raphaely",
"To": "Neena Kochlar",
"pic": "deb_avatar",
"Details": ""
}
},
{
"attr": {
"id": "action2",
"type": "fa fa-info",
"empId": "101",
"ActionDate": "on 19-Apr-2017 18:20:32",
"Action": "Approve",
"From": "Neena Kochlar",
"To": "James",
"pic": "neena_avatar",
"Details": ""
}
}
]
}, {
"attr": {
"id": "action",
"name": "Action History"
},
"children": [{
"attr": {
"id": "action1",
"type": "fa fa-info",
"empId": "101",
"ActionDate": "on 18-Apr-2017 18:20:32",
"Action": "Submit",
"From": "Deb Raphaely",
"To": "Neena Kochlar",
"pic": "deb_avatar",
"Details": ""
}
},
{
"attr": {
"id": "action2",
"type": "fa fa-info",
"empId": "101",
"ActionDate": "on 19-Apr-2017 18:20:32",
"Action": "Approve",
"From": "Neena Kochlar",
"To": "James",
"pic": "neena_avatar",
"Details": ""
}
}
]
}
]
}
我厌倦了转换 JSON 格式,它适用于长度 = 1 的 JSON 数组。对于更大的数组长度,它不起作用。这是我的代码 https://jsfiddle.net/72mz5zft/