Skip to content

Commit

Permalink
Fix-bug: option nodeChilidren is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
dabeng committed Jul 29, 2016
1 parent 1e13288 commit 834c04c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions dist/js/jquery.orgchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@
var children = data[opts.nodeChildren]
data.relationship = flags + (children && children.length > 0 ? 1 : 0);
if (children) {
children.forEach(function(item) {
attachRel(item, '1' + (children.length > 1 ? 1 :0), opts);
});
children.forEach(function(item) {
attachRel(item, '1' + (children.length > 1 ? 1 :0), opts);
});
}
return data;
}
Expand Down
17 changes: 9 additions & 8 deletions examples/js/jquery.orgchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
if (data instanceof $) { // ul datasource
buildHierarchy($chart, buildJsonDS(data.children()), 0, opts);
} else { // local json datasource
buildHierarchy($chart, opts.ajaxURL ? data : attachRel(data, '00'), 0, opts);
buildHierarchy($chart, opts.ajaxURL ? data : attachRel(data, '00', opts), 0, opts);
}
} else {
$.ajax({
Expand All @@ -86,7 +86,7 @@
}
})
.done(function(data, textStatus, jqXHR) {
buildHierarchy($chart, opts.ajaxURL ? data : attachRel(data, '00'), 0, opts);
buildHierarchy($chart, opts.ajaxURL ? data : attachRel(data, '00', opts), 0, opts);
})
.fail(function(jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
Expand Down Expand Up @@ -230,12 +230,13 @@
return subObj;
}

function attachRel(data, flags) {
data.relationship = flags + (data.children ? 1 : 0);
if (data.children) {
data.children.forEach(function(item) {
attachRel(item, '1' + (data.children.length > 1 ? 1 :0));
});
function attachRel(data, flags, opts) {
var children = data[opts.nodeChildren]
data.relationship = flags + (children && children.length > 0 ? 1 : 0);
if (children) {
children.forEach(function(item) {
attachRel(item, '1' + (children.length > 1 ? 1 :0), opts);
});
}
return data;
}
Expand Down

0 comments on commit 834c04c

Please sign in to comment.