【问题标题】:JSON to create a tree with getorgchartJSON 使用 getorgchart 创建树
【发布时间】:2018-05-31 07:20:31
【问题描述】:

我使用 getOrgChart 创建树。 我想用 JSON 来做,只是它不保持键的顺序。 真的有必要像示例中那样有一个有序的 JSON 吗?

(ID;姓名;职务;...)

([{"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"}]);

因为在我这边,在创建自动创建的 JSON 时,我将 id 放在第二位,并且我读到我们无法更改顺序。

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

【问题讨论】:

    标签: getorgchart


    【解决方案1】:

    您可以明确指定 idField 和 parentIdField

    这是一个例子:

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

    【讨论】:

      猜你喜欢
      • 2016-09-03
      • 1970-01-01
      • 2018-05-23
      • 2016-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-08
      • 2011-03-10
      相关资源
      最近更新 更多