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

时间:2011-07-23 18:44:57

标签: javascript jquery google-visualization

我正在使用谷歌组织结构图来构建类似于附加屏幕截图的图表 enter image description here

有一个名为removeRow(nodeIndex)的方法,用于从图表中删除节点,但问题是此方法仅删除节点,而不删除节点的子元素。
所以,例如当用户选择3并单击删除时,我想创建一个删除(3,7,8,9,10)而不仅仅是3的功能。
我尝试创建此功能,这是我的代码:

 <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;
      }

但没有任何事情发生。 我的问题是:我如何创建一个函数来返回所有选定节点子节点的数组,以及每个子节点的chilren(在这个例子中是返回的数组:(3,7,8,9,10))?
谢谢

1 个答案:

答案 0 :(得分:0)

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

childs1=childs1.concat(childs2); 
相关问题