【问题标题】:Keep current node open and collapse other nodes in GetOrgChart保持当前节点打开并折叠 GetOrgChart 中的其他节点
【发布时间】:2017-05-28 18:59:00
【问题描述】:

我正在使用GetOrgChart 创建组织结构图。

一切运行顺利,但是,它不允许您折叠其他节点并保持当前节点打开。

请查看JSFiddle 示例,我从那里获取演示。

在他们的documentation 中列出了一种方法expandOrCollapse,但是没有详细说明它是如何工作的。

我只是想知道这在 GetOrgChart 组件中是否可行。

提前致谢。

【问题讨论】:

    标签: javascript jquery jquery-plugins orgchart


    【解决方案1】:

    你可以使用expand方法。

    这里是方法expand(node, callback)的签名

    • node – 是节点对象,如果知道要展开的节点的id,则节点对象为orgchart.nodes[“expandToThisId”]
    • callback – 将orgchart展开到动画的指定节点,动画完成时会调用callback方法

    还有例子:

            var orgchart = new getOrgChart(document.getElementById("people"),{		
            		expandToLevel: 2,
                scale: 0.5,
                dataSource: [
                    { id: 1, parentId: null, Name: "1"},
                    { id: 2, parentId: 1, Name: "2"},
                    { id: 3, parentId: 1, Name: "3"},
                    { id: 4, parentId: 2, Name: "4"},
                    { id: 5, parentId: 2, Name: "5"},
                    { id: 6, parentId: 3, Name: "6"},
                    { id: 7, parentId: 3, Name: "7"},
                    { id: 8, parentId: 5, Name: "8"},
                    { id: 9, parentId: 5, Name: "9"}]
            });
            
            orgchart.expand(orgchart.nodes["5"]);
            
    html, body {margin: 0px; padding: 0px;height: 100%; overflow: hidden; }
    #people {width: 100%;height: 100%; }
    <link href="http://www.getorgchart.com/GetOrgChart/getorgchart/getorgchart.css" rel="stylesheet"/>
    <script src="http://www.getorgchart.com/GetOrgChart/getorgchart/getorgchart.js"></script>
    <div id="people"></div>

    【讨论】:

    • 缪斯:你能解释一下expand方法是如何折叠相应的节点并保持被点击的元素展开的吗?在您的示例中,当我单击节点 3 时,节点 2 没有折叠,节点 2 也保持打开状态。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-08
    • 1970-01-01
    • 1970-01-01
    • 2019-10-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多