使用 orgchart 时出错:无法读取 属性 '_aZ' of null

Error while using orgchart: Cannot read property '_aZ' of null

我正尝试在 http://www.getorgchart.com

使用这个组织结构图库

少数节点工作完美,但是,当我尝试加载整个组织(大约 1100 个具有多个嵌套级别的主题)时,我收到此控制台错误:

未捕获类型错误:无法读取 属性 '_aZ' of null

并且无法显示图表。

我们将不胜感激任何帮助。 谢谢!

经过一番研究,我已经解决了这个问题。

问题是您首先需要按 parents 排序的数据源(这在文档中没有说明);让我们看一下 initialize on the client 在线演示中的这个例子:


    $('#people').getOrgChart({
    theme: "vivian",
    primaryColumns: ["name", "title", "phone", "mail", "postcode"],
    imageColumn: "image",
    gridView: true,
    dataSource:[            
        { id: 1, parentId: null, name: "Elizabeth Horton", title: "Founder", phone: "(03) 9252 4642" , image: "images/f-46.jpg", mail:"elizabeth.horton@live.com", postcode: "PH2 2SR" },
        { id: 2, parentId: 1, name: "Emily Horton", title: "Fork lift operator", phone: "(08) 9015 4407", image: "images/f-45.jpg", mail:"emily.horton@live.com", postcode: "BA5 0AP"  },
        { id: 3, parentId: 1, name: "Robert Nolan", title: "Blockmason", phone: "(02) 6747 7998", image: "images/f-41.jpg", mail:"robert.nolan@live.com", postcode: "BH9 4NG"  },
        { id: 4, parentId: 1, name: "Callum Anderson", title: "System operator", phone: "(03) 5314 0473", image: "images/f-43.jpg", mail:"callum.anderson@live.com", postcode: "HR6 8ZF"  },
        { id: 5, parentId: 4, name: "Courtney John", title: "System operator", phone: "(03) 5314 0473", image: "images/f-42.jpg", mail:"courtney.john@live.com", postcode: "OL4 6WF"  }
    ]
});

如果我将组织负责人 Elizabeth Horton 的顺序更改为数据源的底部,例如:


$('#people').getOrgChart({
    theme: "vivian",
    primaryColumns: ["name", "title", "phone", "mail", "postcode"],
    imageColumn: "image",
    gridView: true,
    dataSource:[            
        { id: 2, parentId: 1, name: "Emily Horton", title: "Fork lift operator", phone: "(08) 9015 4407", image: "images/f-45.jpg", mail:"emily.horton@live.com", postcode: "BA5 0AP"  },
        { id: 3, parentId: 1, name: "Robert Nolan", title: "Blockmason", phone: "(02) 6747 7998", image: "images/f-41.jpg", mail:"robert.nolan@live.com", postcode: "BH9 4NG"  },
        { id: 4, parentId: 1, name: "Callum Anderson", title: "System operator", phone: "(03) 5314 0473", image: "images/f-43.jpg", mail:"callum.anderson@live.com", postcode: "HR6 8ZF"  },
        { id: 5, parentId: 4, name: "Courtney John", title: "System operator", phone: "(03) 5314 0473", image: "images/f-42.jpg", mail:"courtney.john@live.com", postcode: "OL4 6WF"  },
        { id: 1, parentId: null, name: "Elizabeth Horton", title: "Founder", phone: "(03) 9252 4642" , image: "images/f-46.jpg", mail:"elizabeth.horton@live.com", postcode: "PH2 2SR" }
    ]
});

我遇到了这个错误:

Uncaught TypeError: Cannot read property '_aZ' of null

所以我希望回答我自己的问题可以帮助其他遇到同样问题的人。

干杯!

除了在 children 之前定义 parents 之外,如果您不想在 1100 人的 JSON 数据中硬编码 idparentId 值手动构造您还需要对 getorgchart.js 进行以下修改:

来自这里:

getOrgChart.prototype.loadFromJSON = function(c) {
    this._aB = [];
    this._a9 = 0;
    this._a8 = 0;
    this._au = [];
    this._aj = [];
    this._aO = [];
    this._a7 = new getOrgChart.person(-1, null, null, 2, 2);
    for (var a = 0; a < c.length; a++) {
        var e = c[a];
        var b = e[Object.keys(e)[0]];
        var d = e[Object.keys(e)[1]];
        delete e[Object.keys(e)[0]];
        delete e[Object.keys(e)[0]];
        this.createPerson(b, d, e)
    }
    this.draw()
};

为此:

getOrgChart.prototype.loadFromJSON = function(c) {
    this._aB = [];
    this._a9 = 0;
    this._a8 = 0;
    this._au = [];
    this._aj = [];
    this._aO = [];
    this._a7 = new getOrgChart.person(-1, null, null, 2, 2);
    for (var a = 0; a < c.length; a++) {
        var e = c[a];
        var b = e['id'];
        var d = e['parentId'];
        delete e['id'];
        delete e['parentId'];
        this.createPerson(b, d, e)
    }
    this.draw()
};

Object.keys(e)[0]Object.keys(e)[1] 假设 idparentId 是 "person" objects 中的前两个键,如果您没有先定义它们,实际上不会是真的。

将代码更新为以下内容允许您在初始化之前动态生成 dataSource 参数。