Skip to content

Commit 2b9cc7a

Browse files
committed
add param includeNodeData for getHierarchy()
1 parent da9c838 commit 2b9cc7a

File tree

7 files changed

+91
-9
lines changed

7 files changed

+91
-9
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,13 @@ var oc = $('#chartContainerId').orgchart(options);
309309
<td>false</td>
310310
<td>It enable the export button for orgchart.</td>
311311
</tr>
312+
<tr>
313+
<td>exportButtonName</td>
314+
<td>string</td>
315+
<td>no</td>
316+
<td>"Export"</td>
317+
<td>It's export button name.</td>
318+
</tr>
312319
<tr>
313320
<td>exportFilename</td>
314321
<td>string</td>
@@ -471,6 +478,22 @@ Removes the designated node and its descedant nodes.
471478

472479
#### getHierarchy()
473480
This method is designed to get the hierarchy relationships of orgchart for further processing. For example, after editing the orgchart, you could send the returned value of this method to server-side and save the new state of orghcart.
481+
<table>
482+
<tr>
483+
<th>Name</th>
484+
<th>Type</th>
485+
<th>Required</th>
486+
<th>Default</th>
487+
<th>Description</th>
488+
</tr>
489+
<tr>
490+
<td>includeNodeData</td>
491+
<td>Boolean</td>
492+
<td>No</td>
493+
<td>false</td>
494+
<td>This optional parameter determines whether include the nodeData items in the generated JSON object in addition to the id and children</td>
495+
</tr>
496+
</table>
474497

475498
#### hideParent($node)
476499
This method allows you to hide programatically the parent node of any specific node(.node element), if it has.

README.zh-cn.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,13 @@ var oc = $('#chartContainerId').orgchart(options);
300300
<td>false</td>
301301
<td>启用该选项,插件会追加“导出”按钮到组织结构图的容器DIV里。</td>
302302
</tr>
303+
<tr>
304+
<td>exportButtonName</td>
305+
<td>string</td>
306+
<td>否</td>
307+
<td>"Export"</td>
308+
<td>导出按钮的名字。</td>
309+
</tr>
303310
<tr>
304311
<td>exportFilename</td>
305312
<td>string</td>
@@ -463,6 +470,23 @@ Adds parent node(actullay it's always root node) for current orgchart.
463470
#### getHierarchy()
464471
这个方法被设计用来提供组织结构图的层次结构关系。举个例子,当你采取某种手段对当前的组织结构图的结构进行了改动后,可以调用本方法获得最新的结构,并将其保存到后台。
465472

473+
<table>
474+
<tr>
475+
<th>名称</th>
476+
<th>类型</th>
477+
<th>必填</th>
478+
<th>默认值</th>
479+
<th>描述</th>
480+
</tr>
481+
<tr>
482+
<td>includeNodeData</td>
483+
<td>Boolean</td>
484+
<td>否</td>
485+
<td>false</td>
486+
<td>如果传入的该参数为true,那么导出的层次结构对象中就加入nodeData数据。</td>
487+
</tr>
488+
</table>
489+
466490
#### hideParent($node)
467491
隐藏指定节点的父节点。当然其兄弟节点及祖先节点也一并隐藏了。
468492
<table>

README.zh-tw.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,13 @@ var oc = $('#chartContainerId').orgchart(options);
300300
<td>false</td>
301301
<td>啓用該選項,插件會追加“導出”按鈕到組織結構圖的容器DIV裏。</td>
302302
</tr>
303+
<tr>
304+
<td>exportButtonName</td>
305+
<td>string</td>
306+
<td>否</td>
307+
<td>"Export"</td>
308+
<td>導出按鈕的名字。</td>
309+
</tr>
303310
<tr>
304311
<td>exportFilename</td>
305312
<td>string</td>
@@ -463,6 +470,23 @@ Adds parent node(actullay it's always root node) for current orgchart.
463470
#### getHierarchy()
464471
這個方法被設計用來提供組織結構圖的層次結構關系。舉個例子,當你采取某種手段對當前的組織結構圖的結構進行了改動後,可以調用本方法獲得最新的結構,並將其保存到後台。
465472

473+
<table>
474+
<tr>
475+
<th>名稱</th>
476+
<th>類型</th>
477+
<th>必填</th>
478+
<th>默認值</th>
479+
<th>描述</th>
480+
</tr>
481+
<tr>
482+
<td>includeNodeData</td>
483+
<td>Boolean</td>
484+
<td>否</td>
485+
<td>false</td>
486+
<td>如果傳入的該參數爲true,那麽導出的層次結構對象中就加入nodeData數據。</td>
487+
</tr>
488+
</table>
489+
466490
#### hideParent($node)
467491
隱藏指定節點的父節點。當然其兄弟節點及祖先節點也一並隱藏了。
468492
<table>

dist/js/jquery.orgchart.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
'visibleLevel': 999,
2828
'chartClass': '',
2929
'exportButton': false,
30+
'exportButtonName': 'Export',
3031
'exportFilename': 'OrgChart',
3132
'exportFileextension': 'png',
3233
'parentNodeSymbol': 'oci-leader',
@@ -127,7 +128,7 @@
127128
var that = this;
128129
var $exportBtn = $('<button>', {
129130
'class': 'oc-export-btn' + (this.options.chartClass !== '' ? ' ' + this.options.chartClass : ''),
130-
'text': 'Export',
131+
'text': this.options.exportButtonName,
131132
'click': function(e) {
132133
e.preventDefault();
133134
that.export();
@@ -365,18 +366,26 @@
365366
return data;
366367
},
367368
//
368-
loopChart: function ($chart) {
369+
loopChart: function ($chart, includeNodeData) {
370+
includeNodeData = (includeNodeData !== null && includeNodeData !== undefined) ? includeNodeData : false;
369371
var that = this;
370372
var $tr = $chart.find('tr:first');
371373
var subObj = { 'id': $tr.find('.node')[0].id };
374+
if (includeNodeData) {
375+
var $node = $($tr.find('.node')[0])
376+
$.each($node.data('nodeData'), function (key, value) {
377+
subObj[key] = value;
378+
});
379+
}
372380
$tr.siblings(':last').children().each(function() {
373381
if (!subObj.children) { subObj.children = []; }
374-
subObj.children.push(that.loopChart($(this)));
382+
subObj.children.push(that.loopChart($(this), includeNodeData));
375383
});
376384
return subObj;
377385
},
378386
//
379-
getHierarchy: function () {
387+
getHierarchy: function (includeNodeData) {
388+
includeNodeData = (includeNodeData !== null && includeNodeData !== undefined) ? includeNodeData : false;
380389
if (typeof this.$chart === 'undefined') {
381390
return 'Error: orgchart does not exist'
382391
} else {
@@ -395,7 +404,7 @@
395404
}
396405
}
397406
}
398-
return this.loopChart(this.$chart);
407+
return this.loopChart(this.$chart, includeNodeData);
399408
},
400409
// detect the exist/display state of related node
401410
getNodeState: function ($node, relation) {

dist/js/jquery.orgchart.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/jquery.orgchart.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/jquery.orgchart.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@
366366
return data;
367367
},
368368
//
369-
loopChart: function ($chart, includeNodeData = false) {
369+
loopChart: function ($chart, includeNodeData) {
370+
includeNodeData = (includeNodeData !== null && includeNodeData !== undefined) ? includeNodeData : false;
370371
var that = this;
371372
var $tr = $chart.find('tr:first');
372373
var subObj = { 'id': $tr.find('.node')[0].id };
@@ -383,7 +384,8 @@
383384
return subObj;
384385
},
385386
//
386-
getHierarchy: function (includeNodeData = false) {
387+
getHierarchy: function (includeNodeData) {
388+
includeNodeData = (includeNodeData !== null && includeNodeData !== undefined) ? includeNodeData : false;
387389
if (typeof this.$chart === 'undefined') {
388390
return 'Error: orgchart does not exist'
389391
} else {

0 commit comments

Comments
 (0)