js方法--目录树

  1<!--    
  2    /**
  3    *数据存放地--单节点
  4
  5    *id     公司ID
  6    *name   公司名称
  7    *level  级别
  8    *stat   此节点是否展开
  9    *index  序列号
 10
 11    */

 12    function codes(id,name,level,stat,index){
 13        this.id=id;
 14          this.name=name;
 15          this.level=level;
 16          this.stat=stat;
 17          this.index=index;
 18    }

 19    /**得到此节点的缩进量*/
 20    function getNbsp(count){
 21        var nbsp="";
 22        for(var i=0;i<count;i++){
 23            nbsp=nbsp+"&nbsp;&nbsp;&nbsp;&nbsp;";
 24        }

 25        return nbsp;
 26    }

 27    
 28    /**得到此节点是否显示*/
 29    function getShowFlag(index){
 30        var level=_tree[index].level;
 31        for(var i=index-1;i>=0;i--){
 32            if(level*1>_tree[i].level*1){
 33                if(_tree[i].stat==0){
 34                    return false;
 35                }

 36                level--;
 37            }

 38        }

 39        return true;
 40    }

 41    
 42    /**再次刷新*/
 43    function ReLoad(index){
 44        if(_tree[index].stat=='1'){
 45            _tree[index].stat='0';
 46        }
else{
 47            _tree[index].stat='1';
 48        }

 49        TreeLoad();
 50    }

 51    
 52    /**刷新函数*/
 53    function TreeLoad(){
 54        var context="";
 55        var nbsp="";
 56        //已经被捕捉到的节点数
 57        var foreachNum=0;
 58        var arrayList = window.dialogArguments;
 59        //alert(arrayList);
 60        //var objList="1.1";
 61        //需要被捕捉的节点数组
 62        //var arrayList=objList.split('.');
 63        for(var i=0;i<_tree.length;i++){
 64            if(getShowFlag(_tree[i].index)){
 65                /**图片*/
 66                var img="<img src='/iPsaPro/Images/close.gif' border='0'>";
 67                if(_tree[i].stat==1){
 68                    img="<img src='/iPsaPro/Images/open.gif' border='0'>";
 69                }

 70                /**缩进*/
 71                nbsp=getNbsp(_tree[i].level);
 72                /**已选节点大于遍历到的选中节点foreachNum<arrayList.length*/
 73                //如果传来的数组为空,直接遍历节点
 74                if(arrayList[0]=="" || arrayList[0]==null){
 75                    context=context+nbsp+"<a href='#'onclick='javascript:ReLoad("+_tree[i].index+")'>"+img+"</a><input name='Checkbox' type='checkbox' value=\""+_tree[i].id+"^"+_tree[i].name+"\"   />"+_tree[i].name+"<br>";
 76
 77                }

 78                else{
 79                    //已捕捉的节点<需要捕捉的节点 继续捕捉
 80                    if(foreachNum<arrayList.length){
 81                        var temp=0;
 82                        for(var j=0;j<arrayList.length;j++){
 83                            if(_tree[i].id==arrayList[j]){
 84                                 foreachNum+=1;
 85                                 temp+=1;
 86                                 context=context+nbsp+"<a href='#'onclick='javascript:ReLoad("+_tree[i].index+")'>"+img+"</a><input name='Checkbox' checked=true type='checkbox' value=\""+_tree[i].id+"^"+_tree[i].name+"\"   />"+_tree[i].name+"<br>";
 87                                 break;
 88                            }

 89                        }

 90                        if(temp==0){
 91                            context=context+nbsp+"<a href='#'onclick='javascript:ReLoad("+_tree[i].index+")'>"+img+"</a><input name='Checkbox' type='checkbox' value=\""+_tree[i].id+"^"+_tree[i].name+"\"   />"+_tree[i].name+"<br>";                        
 92                        }

 93                    }

 94                    else{
 95                        context=context+nbsp+"<a href='#'onclick='javascript:ReLoad("+_tree[i].index+")'>"+img+"</a><input name='Checkbox' type='checkbox' value=\""+_tree[i].id+"^"+_tree[i].name+"\"   />"+_tree[i].name+"<br>";
 96                    }

 97                }

 98            }

 99        }

100        document.getElementById('TreeContainer').innerHTML=context;        
101    }

102    
103    
104    
105    /**点击节点名称,请按照逻辑修改此函数*/
106    TreeLoad();
107    
108    /**SubmitSelectNode()遍历树中的节点*/
109    function SubmitSelectNode(){
110        var values=document.getElementsByName("Checkbox");
111        var array=new Array();
112        var temp=0;
113        for(var i=0;i<values.length;i++){
114            if(values[i].type=="checkbox"){
115                if(values[i].checked==true){
116                    array[temp]=values[i].value;
117                    temp+=1;
118                }

119            }

120        }

121        //alert('返回的变量'+array);
122        window.returnValue=array;
123        window.close();
124    }

125
126

posted on 2007-05-21 16:25  散步的蠕虫  阅读(889)  评论(0编辑  收藏  举报

导航