2017-05-19 2 views
0

Ich möchte eines unter JSON-Format in das entsprechende JSON-Format konvertieren. Die Json ich von Rast Dienstleistungen erhalten nicht die design.I müde unterstützt die folgenden ListenansichtKonvertiere ein JSON-Format in ein anderes

http://www.oracle.com/webfolder/technetwork/jet/jetCookbook.html?component=listView&demo=jsonHierListView

JSON-Format (I erhalten von Ruhe Dienstleistungen)

{ 
    "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-Format Ich brauche zu implementieren

{ 
    "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": "" 
      } 
     } 

     ] 
    } 
    ] 
} 

ich müde, um das JSON-Format und es funktionierte gut für JSON-Array mit einer Länge = 1. für größere Feldlänge es nicht funktioniert zu konvertieren. Hier ist mein Code https://jsfiddle.net/72mz5zft/

+0

Bitte siehe [* Wie eine minimale, komplett erstellen und verifizierbares Beispiel *] (http://stackoverflow.com/help/mcve) und [* Wie stelle ich eine gute Frage? *] (http://stackoverflow.com/help/how-to-ask) – RobG

Antwort

0

Ich denke, im Wesentlichen, was Sie versuchen, ist ziemlich einfache Zuordnung zu tun:

var person={"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": { \t \t 
 
     "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":"" 
 
     } 
 
     }, 
 
     {"childrenItem": { \t \t 
 
     "id": "action2", 
 
     "type": "fa fa-info", 
 
     "empId": "101", 
 
     "ActionDate": "", 
 
     "Action": "Pending", 
 
     "From": "James", 
 
     "To":"", 
 
     "pic":"james_avatar", 
 
     "Details":"" 
 
     } 
 
     } 
 
    ] 
 
    } 
 
]}; 
 

 
var result = { 
 
    ActionHistory: person.ActionHistory.map(function(item){ 
 
     return {attr: { 
 
      id: item.id, 
 
      name: item.name, 
 
      children: item.children.map(function(child){ 
 
       return { 
 
        attr: child.childrenItem 
 
       } 
 
      }) 
 
     }} 
 
    }) 
 
}; 
 

 
console.log(result);

+0

Vielen Dank Jamiec.Es hat gut funktioniert. Vielen Dank für Ihre schnelle Antwort – CodeWriter

Verwandte Themen