Javascript 如何在OrgChart中隐藏子节点和显示父节点

Javascript 如何在OrgChart中隐藏子节点和显示父节点,javascript,orgchart,Javascript,Orgchart,我目前正在实现dabeng的OrgChart(),希望在加载组织结构图时显示父节点并隐藏子节点 我有以下代码,假设添加了显示父节点的选项,但是这不起作用: $.fn.orgchart = function (options) { var defaultOptions = { 'nodeTitle': 'name', 'nodeUIMID': 'uim_id', 'nodeJobTitle': 'title',

我目前正在实现dabeng的OrgChart(),希望在加载组织结构图时显示父节点并隐藏子节点

我有以下代码,假设添加了显示父节点的选项,但是这不起作用:

$.fn.orgchart = function (options) {
        var defaultOptions = {
            'nodeTitle': 'name',
            'nodeUIMID': 'uim_id',
            'nodeJobTitle': 'title',
            'nodeFaculty': 'faculty',
            'nodeDepartment': 'department',
            'nodeSubSection': 'sub_section',
            'nodeUrl': 'url',
            'nodeId': 'id',
            'toggleSiblingsResp': false,
            'depth': 999,
            'chartClass': '',
            'exportButton': false,
            'exportFilename': 'OrgChart',
            'exportFileextension': 'png',
            'draggable': false,
            'direction': 't2b',
            'pan': true,
            'zoom': true,
            'zoominLimit': 2,
            'zoomoutLimit': 0.5,
            'showParent': true,
            'hideChildren': true
        };

        switch (options) {
            case 'showParent':
            return showParent.apply(this, Array.prototype.splice.call(arguments, 1));
        case 'hideChildren':
            return hideChildren.apply(this, Array.prototype.splice.call(arguments, 1));
            default: // initiation time
                var opts = $.extend(defaultOptions, options);
        }

        // build the org-chart
        var $chartContainer = this;
        var data = opts.data;
        var $chart = $('<div>', {
            'data': { 'options': opts },
            'class': 'orgchart' + (opts.chartClass !== '' ? ' ' + opts.chartClass : '') + (opts.direction !== 't2b' ? ' ' + opts.direction : ''),
            'click': function (event) {
                if (!$(event.target).closest('.node').length) {
                    $chart.find('.node.focused').removeClass('focused');
                }
            }
        });
$.fn.orgchart=函数(选项){
var defaultOptions={
“nodeTitle”:“name”,
'nodeUIMID':'uim_id',
“nodejobstitle”:“title”,
“nodeFaculty”:“faculty”,
“nodeDepartment”:“department”,
“节点子节”:“子节”,
'nodeUrl':'url',
'nodeId':'id',
“toggleSiblingsResp”:false,
深度:999,
“chartClass”:“,
“exportButton”:false,
“exportFilename”:“OrgChart”,
“exportFileextension”:“png”,
“可拖动”:错误,
“方向”:“t2b”,
"潘":对,,
“缩放”:正确,
“zoominLimit”:2,
“zoomoutLimit”:0.5,
“showParent”:正确,
“隐藏儿童”:对
};
开关(选项){
案例“showParent”:
返回showParent.apply(这个,Array.prototype.splice.call(参数,1));
“hideChildren”一案:
返回hideChildren.apply(this,Array.prototype.splice.call(arguments,1));
默认启动时间
var opts=$.extend(defaultOptions,options);
}
//构建组织结构图
var$chartContainer=this;
var数据=选择数据;
变量$chart=$(''{
'data':{'options':opts},
'class':'orgchart'+(opts.chartClass!=''?''+opts.chartClass:'')+(opts.direction!=='t2b'?''+opts.direction:''),
“单击”:函数(事件){
if(!$(event.target).closest('.node').length){
$chart.find('.node.focused').removeClass('focused');
}
}
});

构建图表时是否需要调用showParent函数?

@user3565164您可以使用以下代码段:

var oc = $('#chartContainerId').orgchart({
  ...

  'initCompleted': function() {
    oc.hideChildren($('#chart-container').find('.node:first'));
  }
});