Skip to content

Commit

Permalink
Merge pull request #42 from jburbach/children-override
Browse files Browse the repository at this point in the history
use nodeChildren option when determining relationship
  • Loading branch information
dabeng authored Jul 29, 2016
2 parents 1d1a934 + 4a552b0 commit 1e13288
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions dist/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,11 +230,12 @@
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 1e13288

Please sign in to comment.