|
29 | 29 | var defaultOptions = { |
30 | 30 | 'nodeTitle': 'name', |
31 | 31 | 'nodeId': 'id', |
32 | | - 'nodeChildren': 'children', |
33 | 32 | 'toggleSiblingsResp': false, |
34 | 33 | 'depth': 999, |
35 | 34 | 'chartClass': '', |
|
75 | 74 | if (data instanceof $) { // ul datasource |
76 | 75 | buildHierarchy($chart, buildJsonDS(data.children()), 0, opts); |
77 | 76 | } else { // local json datasource |
78 | | - buildHierarchy($chart, opts.ajaxURL ? data : attachRel(data, '00', opts), 0, opts); |
| 77 | + buildHierarchy($chart, opts.ajaxURL ? data : attachRel(data, '00'), 0, opts); |
79 | 78 | } |
80 | 79 | } else { |
81 | 80 | $.ajax({ |
|
86 | 85 | } |
87 | 86 | }) |
88 | 87 | .done(function(data, textStatus, jqXHR) { |
89 | | - buildHierarchy($chart, opts.ajaxURL ? data : attachRel(data, '00', opts), 0, opts); |
| 88 | + buildHierarchy($chart, opts.ajaxURL ? data : attachRel(data, '00'), 0, opts); |
90 | 89 | }) |
91 | 90 | .fail(function(jqXHR, textStatus, errorThrown) { |
92 | 91 | console.log(errorThrown); |
|
230 | 229 | return subObj; |
231 | 230 | } |
232 | 231 |
|
233 | | - function attachRel(data, flags, opts) { |
234 | | - var children = data[opts.nodeChildren] |
235 | | - data.relationship = flags + (children && children.length > 0 ? 1 : 0); |
236 | | - if (children) { |
237 | | - children.forEach(function(item) { |
238 | | - attachRel(item, '1' + (children.length > 1 ? 1 :0), opts); |
| 232 | + function attachRel(data, flags) { |
| 233 | + data.relationship = flags + (data.children && data.children.length > 0 ? 1 : 0); |
| 234 | + if (data.children) { |
| 235 | + data.children.forEach(function(item) { |
| 236 | + attachRel(item, '1' + (data.children.length > 1 ? 1 : 0)); |
239 | 237 | }); |
240 | 238 | } |
241 | 239 | return data; |
|
761 | 759 | function buildHierarchy ($appendTo, nodeData, level, opts, callback) { |
762 | 760 | var $table; |
763 | 761 | // Construct the node |
764 | | - var $childNodes = nodeData[opts.nodeChildren]; |
| 762 | + var $childNodes = nodeData.children; |
765 | 763 | var hasChildren = $childNodes ? $childNodes.length : false; |
766 | 764 | if (Object.keys(nodeData).length > 1) { // if nodeData has nested structure |
767 | 765 | $table = $('<table>'); |
|
0 commit comments