站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Javascript 专题Javascript利用递归生成企业部门树结构

Javascript利用递归生成企业部门树结构

摘要: Javascript利用递归生成企业部门树结构
<textarea readonly style="border:none;font-family:Courier New;line-height:150%;width:760px;overflow-y:visible">

ID ParentID Name结构的数据
Javascript脚本递归函数生成部门树结构




/*----------------------------文件---------------------*/

<script>
var Sys_Group = new Array();
var MaxStack;

Sys_Group[0] = new Array(1, 0, "总经司");
Sys_Group[1] = new Array(2, 1, "人事部");
Sys_Group[2] = new Array(6, 1, "人sdsd事部");
Sys_Group[3] = new Array(4, 2, "人1事部");
Sys_Group[4] = new Array(3, 2, "人2事部");
Sys_Group[5] = new Array(5, 3, "人3事部");
Sys_Group[6] = new Array(7, 1, "财和事部");
Sys_Group[7] = new Array(8, 5, "财和事ds部");
Sys_Group[8] = new Array(9, 3, "财和sd事ds部");
MaxStack=9;
var str;
var Old_Group=new Array(),Yu_Group =new Array();
for(var i=0; iOld_Group[i]=new Array(null, null, null);
}
i=0;
Yu_Group=Sys_Group;
str='<table border="0" id=T0 align="center" cellpadding="0" cellspacing="0" class="inline">';
str+=' <tr>';
str+=' <td align="left" valign="top"></td>';
str+=' </tr>';
str+=' <tr>';
str+=' <td align="center" valign="top"></td>';
str+=' </tr>';
str+=' <tr>';
str+=' <td align="center" valign="top" class="sectionPaddig"><table width="80" height="30" border="0" align="center" cellpadding="0" cellspacing="0" class="inline" >';
str+=' <tr>';
str+=' <td align="center" onclick="openDlg('+Sys_Group[0][0]+');return;T0.style.display=\'none\';" class="sectionStyle1">'+Sys_Group[0][2]+'</td>';
str+=' </tr>';
str+=' </table>';
str+=' </td>';
str+=' </tr>';
str+=' <tr>';
str+=' <td align="center" valign="top">';
if (MaxStack>1){
str+='<table border="0" cellpadding="0" cellspacing="0" bgcolor=#000000 width=1 height=15 class="inline" >';
str+=' <tr>';
str+=' <td align=center>';
str+=' </td>';
str+=' </tr>';
str+=' </table>';
}
str+=' </td>';
str+=' </tr>';
str+=' <tr>';
str+=' <td align="center" valign="top">';

Old_Group[0]=Yu_Group[0];
Yu_Group[0]=new Array(null, null, null);
Grouplist(1,0);
str+=' </td>';
str+=' </tr>';
str+='</table>';

//alert(str);
document.write(str);

function Grouplist(InGroup_ID,A){
var Old_Find,Yu_Find,YuID_Find,TempGroup_ID,TestStr;
if (A==MaxStack){
return;
}
for(var i=0; i if (Yu_Group[i][1]!=null && Yu_Group[i][1]== InGroup_ID ){

str+='<table border="0" id=T'+Sys_Group[i][0]+' align="center" cellpadding="0" cellspacing="0" class="inline">';

for (var j=0; j Old_Find=false;
if (Yu_Group[i][1]!=null && Old_Group[j][1]!=null && Old_Group[j][1]==Yu_Group[i][1]){
Old_Find=true;
break;

}

}
for (var j=0; j Yu_Find=false;
if ( i!=j && Yu_Group[i][1]!=null && Yu_Group[j][1]==Yu_Group[i][1] && Yu_Group[j][0]!=Yu_Group[i][0] ){
Yu_Find=true;
if (i==4){
alert(Yu_Find);
}
break;
}

}
for (var j=0; j YuID_Find=false;
if ( i!=j && Yu_Group[i][1]!=null && Yu_Group[j][1]==Yu_Group[i][0] ){
YuID_Find=true;
break;
}

}

str+=' <tr>';
if (Old_Find==false&&Yu_Find==false){
str+=' <td align="center" valign="top" >';
str+='<table border="0" cellpadding="0" cellspacing="0" bgcolor=#000000 width=1 class="dotbox" >';
str+=' <tr>';
str+=' <td align=center ></td>';
str+=' </tr>';
str+=' </table>';
str+='</td>';
}
if (Old_Find==true&&Yu_Find==false){
str+=' <td align="left" valign="top">';
str+='<table border="0" cellpadding="0" cellspacing="0" bgcolor=#000000 width=50% class="dotbox" >';
str+=' <tr>';
str+=' <td align=center ></td>';
str+=' </tr>';
str+=' </table>';
str+='</td>';
}
if (Old_Find==true&&Yu_Find==true){
str+=' <td align="center" valign="top">';
str+='<table border="0" cellpadding="0" cellspacing="0" bgcolor=#000000 width=100% class="dotbox" >';
str+=' <tr>';
str+=' <td align=center ></td>';
str+=' </tr>';
str+=' </table>';
str+='</td>';
}
if (Old_Find==false&&Yu_Find==true){
str+=' <td align="right" valign="top">';
str+='<table border="0" cellpadding="0" cellspacing="0" bgcolor=#000000 width=50% class="dotbox" >';
str+=' <tr>';
str+=' <td align=center ></td>';
str+=' </tr>';
str+=' </table>';
str+='</td>';
}
str+=' </tr>';
str+=' <tr>';
str+=' <td align="center" valign="top"></td>';
str+=' </tr>';
str+=' <tr>';
str+=' <td align="center" valign="top" class="sectionPaddig"><table width="80" height="30" border="0" align="center" cellpadding="0" cellspacing="0" class="inline" >';
str+=' <tr>';
str+=' <td align="center" onclick="openDlg('+Sys_Group[i][0]+');return;T'+Sys_Group[i][0]+'.style.display=\'none\';" class="sectionStyle1">'+Sys_Group[i][2]+'</td>';
str+=' </tr>';
str+=' </table>';
str+=' </td>';
str+=' </tr>';
str+=' <tr>';
str+=' <td align="center" valign="top">';


if(YuID_Find==true){
str+=' <table border="0" cellpadding="0" cellspacing="0" class="inline" >';
str+=' <tr>';
str+=' <td>';
str+=' ';
str+=' </td>';
str+=' </tr>';
str+=' </table>';
}
str+=' </td>';
str+=' </tr>';
str+=' <tr>';
str+=' <td align="center" valign="top">';

Old_Group[i]=Yu_Group[i];
TempGroup_ID=Yu_Group[i][0];

Yu_Group[i]=new Array(null, null, null);
//alert(TempGroup_ID);

Grouplist(TempGroup_ID,i);

str+=' </td>';
str+=' </tr>';
str+='</table>';
}

}
}


</script>


</textarea>
↑返回目录
前一篇: JavaScript写打开窗口
后一篇: 常用的几个JAVASCRIPT函数,收集中。。。