我正在尝试在http://www.getorgchart.com使用这个组织结构图库
但是,很少有节点可以完美运行,但是,当我尝试加载整个组织(大约 1100 个具有多个嵌套级别的主题)时,我收到此控制台错误:
未捕获的类型错误:无法读取 null 的属性“_aZ”
并且无法显示图表。
任何帮助将不胜感激。谢谢!
我正在尝试在http://www.getorgchart.com使用这个组织结构图库
但是,很少有节点可以完美运行,但是,当我尝试加载整个组织(大约 1100 个具有多个嵌套级别的主题)时,我收到此控制台错误:
未捕获的类型错误:无法读取 null 的属性“_aZ”
并且无法显示图表。
任何帮助将不胜感激。谢谢!
经过一番研究,我已经解决了这个问题。
问题是您首先需要父母订购的数据源(文档中没有说明);让我们看一下初始化客户端在线演示中的这个例子:
$('#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" }
]
});
我收到了这个错误:
未捕获的类型错误:无法读取 null 的属性“_aZ”
所以我希望回答我自己的问题可以帮助其他有同样问题的人。
干杯!
除了在孩子之前定义父母之外,如果您不想在 1100 人 JSON 数据结构中手动硬编码id
和parentId
值,您还需要对以下内容进行修改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
andparentId
是“person”对象中的前两个键,如果您没有先定义它们,则实际上不会是真的。
将代码更新为以下允许您dataSource
在初始化参数之前动态生成参数。