当我尝试加载整个组织(大约1100个具有多个嵌套级别的主题)时,很少有节点可以完美运行,我得到此控制台错误:
未捕获的TypeError:无法读取null的属性'_aZ'
无法显示图表。
任何帮助都会被贬低。 谢谢!
答案 0 :(得分:3)
经过一番研究,我已经解决了这个问题。
问题是您需要先由父母订购您的dataSource(文档中未说明);让我们在 在客户端上初始化 在线演示中查看此示例:
$('#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 的顺序更改为dataSource的底部,如:
$('#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" }
]
});
我收到了这个错误:
未捕获的TypeError:无法读取属性' _aZ'为null
所以我希望回答我自己的问题可以帮助其他人解决同样的问题。
干杯!
答案 1 :(得分:0)
除了在子女之前定义父母之外,如果您不想手动修改1100人JSON数据结构中的id
和parentId
值,您还需要对{{1 }}:
由此:
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]
和id
是“人物”对象中的前两个键,如果您没有先定义它们,则不会实际上是真的。
将代码更新为以下内容可让您在初始化之前动态生成parentId
参数。