Skip to content

Commit da9c838

Browse files
authored
Merge pull request #586 from rmertzpfpt/master
Added option to getHierarchy to include nodeData
2 parents f3d0498 + 0833f07 commit da9c838

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/js/jquery.orgchart.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,18 +366,24 @@
366366
return data;
367367
},
368368
//
369-
loopChart: function ($chart) {
369+
loopChart: function ($chart, includeNodeData = false) {
370370
var that = this;
371371
var $tr = $chart.find('tr:first');
372372
var subObj = { 'id': $tr.find('.node')[0].id };
373+
if (includeNodeData) {
374+
var $node = $($tr.find('.node')[0])
375+
$.each($node.data('nodeData'), function (key, value) {
376+
subObj[key] = value;
377+
});
378+
}
373379
$tr.siblings(':last').children().each(function() {
374380
if (!subObj.children) { subObj.children = []; }
375-
subObj.children.push(that.loopChart($(this)));
381+
subObj.children.push(that.loopChart($(this), includeNodeData));
376382
});
377383
return subObj;
378384
},
379385
//
380-
getHierarchy: function () {
386+
getHierarchy: function (includeNodeData = false) {
381387
if (typeof this.$chart === 'undefined') {
382388
return 'Error: orgchart does not exist'
383389
} else {
@@ -396,7 +402,7 @@
396402
}
397403
}
398404
}
399-
return this.loopChart(this.$chart);
405+
return this.loopChart(this.$chart, includeNodeData);
400406
},
401407
// detect the exist/display state of related node
402408
getNodeState: function ($node, relation) {

0 commit comments

Comments
 (0)