简体   繁体   English

从google org图表中删除所有子元素

[英]remove all child elements from google org chart

i'm using google organization chart to build chart similar to the attached screenshot. 我正在使用谷歌组织结构图来构建类似于附加屏幕截图的图表。
在此输入图像描述

there is a method called removeRow(nodeIndex) that is used to remove a node from chart, but the problem is that this method only remove the node, without removing the child elements of the node. 有一个名为removeRow(nodeIndex)的方法,用于从图表中删除节点,但问题是此方法仅删除节点,而不删除节点的子元素。
so, for example when the user selects 3 and click remove i want to create a function that remove (3,7,8,9,10) and not only 3. 所以,例如当用户选择3并单击删除时,我想创建一个删除(3,7,8,9,10)而不仅仅是3的函数。
i try to create this function and this is my code: 我尝试创建此功能,这是我的代码:

 <script type='text/javascript'>var counter;  var childs1= new Array();</script>
<script>
 $('#remove').click(function(){

          // this method return all childs indexes for the selected node(7,10)   
         childs1=chart.getChildrenIndexes(selected_node);
         counter=childs1.length;
         for(var i=0;i< counter;i++)
             {

                 getChilds(childs1[i]);
             }
            for(var i=0;i< childs1.length;i++)
             {
              data.removeRow(childs1[i]);
             }

       })
      }

      function getChilds(child)
      {
          var childs2=new Array();
          childs2=chart.getChildrenIndexes(child);
          childs1.concat(childs2);
          counter+=childs2.length;
      }

but nothing happend. 但没有任何事情发生。 my question is: how can i create a function that returns array of all selected node children, and the chilren of each child (in this example the returned array :(3,7,8,9,10))? 我的问题是:我如何创建一个函数来返回所有选定节点子节点的数组,以及每个子节点的chilren(在这个例子中返回的数组:(3,7,8,9,10))?
Thank You 谢谢

代码中的问题是我忘了在concat之后引用childs1:

childs1=childs1.concat(childs2); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM