bootstrap treevie只展开一个节点,关闭其他节点
1 //获取当前节点的父节点(包括当前节点) 2 function getAllParentNode(parentNode){ 3 var arry = []; 4 arry.push(parentNode); 5 //boolean i = true; 6 while(true){ 7 parentNode = $("#treeview").treeview("getNode", parentNode.parentId); 8 if(parentNode.nodes) { 9 arry.push(parentNode); 10 } 11 else{ 12 break; 13 } 14 } 15 return arry; 16 } 17 //通过节点找到其父节点的兄弟节点,使其关闭 18 function closeOtherNode(node){ 19 var arry = []; 20 var p = getAllParentNode(node); 21 for(i in p){ 22 var temp=($('#tree').treeview('getSiblings', p[i])); 23 for(k in temp){ 24 arry.push(temp[k]); 25 } 26 } 27 for(j in arry){ 28 $('#tree').treeview('collapseNode', [ arry[j].nodeId, { silent: true, ignoreChildren: false } ]); 29 } 30 }