JSON to create a tree with getorgchart

139 Views Asked by At

I work with getOrgChart to create a tree. I would like to do it in JSON except that it does not keep the order of the keys. Is it really necessary to have an ordered JSON as in the exemple?

(Id; Name; Title; ...)

([{"Id":"1","ParentId":"","Name":"Luke Coleman","Title":"ESL teacher","Address":"31 Dalgarno Street COOCOOBOONAH NSW 2380","Phone":"(02) 6780 6577","Visa":null,"Image":"http://www.getorgchart.com/GetOrgChart/getorgchart-demos/images/f-19.jpg"},{"Id":"2","ParentId":"1","Name":"Zara Potter","Title":"Bricklayer","Address":"74 Main Street RAMCO SA 5322","Phone":null,"Visa":"4556 6703 4539 1908","Image":"http://www.getorgchart.com/GetOrgChart/getorgchart-demos/images/f-20.jpg"},{"Id":"3","ParentId":"1","Name":"Mohammed Cook","Title":"Nursing aide","Address":null,"Phone":"(03) 5300 7404","Visa":"4716 4797 6315 4724","Image":"http://www.getorgchart.com/GetOrgChart/getorgchart-demos/images/f-1.jpg"},{"Id":"4","ParentId":"1","Name":"Harley Birch","Title":"Reservation agent","Address":"70 Cornish Street WILLIAMS RAAF VIC 3027","Phone":"(03) 8336 9859","Visa":"5442 1396 6319 2111","Image":"http://www.getorgchart.com/GetOrgChart/getorgchart-demos/images/f-3.jpg"},{"Id":"5","ParentId":"2","Name":"Maya Ford","Title":"Reservation agent","Address":"70 Cornish Street WILLIAMS RAAF VIC 3027","Phone":"(03) 8336 9859","Visa":"5442 1396 6319 2111","Image":"http://www.getorgchart.com/GetOrgChart/getorgchart-demos/images/f-5.jpg"}]);

Because on my side, when creating the JSON that is created automatically, I get the id in 2nd position and I read that we could not change the order.

{"Statut":"Test","id":106,"Image":"Test.gif","Nom":"Test","Heure":"17-05-2018 14:41:55","parentId":"","Compteur":10000}
1

There are 1 best solutions below

0
On

You can explicitly specify the idField and parentIdField

Here is an example:

var orgChart = new getOrgChart(peopleElement, {
    idField: "id",
    parentIdField: "parentId"
    ...
});