[英]remove all child elements from google org chart
我正在使用谷歌組織結構圖來構建類似於附加屏幕截圖的圖表。
有一個名為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))?
謝謝
代碼中的問題是我忘了在concat之后引用childs1:
childs1=childs1.concat(childs2);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.