【问题标题】:How to hide children nodes and show parent node in OrgChart如何在 OrgChart 中隐藏子节点并显示父节点
【发布时间】:2018-07-29 13:55:32
【问题描述】:

我目前正在实现大鹏的OrgChart (https://github.com/dabeng/OrgChart),想在加载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');
                }
            }
        });

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

【问题讨论】:

    标签: javascript orgchart


    【解决方案1】:

    @user3565164 你可以使用以下代码sn-ps:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多