OrgChart icon indicating copy to clipboard operation
OrgChart copied to clipboard

Having no children element in any element throws error if you use local datasource

Open Aweorih opened this issue 9 years ago • 1 comments

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;  
  });  
}

Aweorih avatar Mar 30 '17 09:03 Aweorih

Same is true when using AJAX/JSON, best bet is to set children to empty array

sbubaron avatar Jun 29 '17 17:06 sbubaron