2011-07-23 27 views
3

我使用谷歌組織圖來構建類似於附加屏幕截圖的圖表。
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; 
     } 

但沒有任何事情發生。 我的問題是:我怎麼能創建一個函數,返回所有選定的節點子節點的數組,以及每個子節點的子節點(在本例中是返回的數組:(3,7,8,9,10))?
謝謝

回答

0

在代碼的問題是,我忘了參考CONCAT後childs1:

childs1=childs1.concat(childs2);