2

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

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

4

1 回答 1

0

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

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

  'initCompleted': function() {
    oc.hideChildren($('#chart-container').find('.node:first'));
  }
});
于 2018-09-07T08:36:15.697 回答