OrgChart
OrgChart copied to clipboard
Having no children element in any element throws error if you use local datasource
It seems that if you use jquery 2 (not much tested but that's the big difference I see at the moment after comparing the example to my use case)
$.each(nodeData.children, function (index, child) {
child.parentId = nodeData.id;
});
at this line throws an error (Uncaught TypeError: Cannot read property 'length' of undefined) if there is any element that has no 'children' attribute if you use local json datasource. Problem could be easily fixed if you wrap a check around it, e.g. changing it to:
if ('undefined' !== typeof nodeData.children) {
$.each(nodeData.children, function (index, child) {
child.parentId = nodeData.id;
});
}
Same is true when using AJAX/JSON, best bet is to set children to empty array