js遞歸調用注意return返回值

[javascript] view plain
轉載:  http://blog.csdn.net/a1017680279/article/details/72953887 copy
  1. 調用:   
  2.             //獲得公司樹結構中的已選中節點  
  3.             var selectedNode = $("#resourceTree").tree('getSelected');  
  4.             //console.log(selectedNode);  
  5.             var rootNode = getTreeRoot(selectedNode);  
  6.             console.log('rootNode====')  
  7.             console.log(rootNode);  
  8.             if(rootNode !=null && rootNode != 'undefined' &&rootNode.text == '金控'){  
  9.                 alert('金控');  
  10.             }else{  
  11.                 alert('非金控');  
  12.             }  
  13. 遞歸方法:  
  14.         //獲得公司結構的節點node對應的最上層節點  
  15.         function getTreeRoot(node){  
  16.             console.log('getTreeRoot====node');  
  17.             console.log(node);  
  18.             var parentNode = $("#resourceTree").tree('getParent',node.target);  
  19.             console.log('getTreeRoot()=====');  
  20.             console.log(parentNode);  
  21.             if (parentNode == null){  
  22.                 console.log('getTreeRoot()=====null');  
  23.                 console.log(node);  
  24.                 return node;  
  25.             }else{  
  26.                 console.log('getTreeRoot====else');  
  27.                 //這裏需要對遞歸方法進行return  
  28.                 return getTreeRoot(parentNode);  
  29.             }  
  30.         }  


轉載:http://blog.csdn.net/a1017680279/article/details/72953887
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章