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

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

ID ParentID Name结构的数据

Javascript脚本递归函数生成部门树结构

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

<style>

p, span, div, table, tr, td, input {

font-family: Tahoma;

font-size: 11px;

}

.sectionPaddig{

padding-left: 4;

padding-right: 4;

FILTER: progid:DXImageTransform.Microsoft.dropShadow( Color=BCBCBC,offX=2,offY=2,positive=true);

}

.inline{

display: inline;

vertical-align :text-top;

}

.dotbox{

display: inline;

height:1px;

}

.sectionStyle1{

padding-left: 2;

padding-right: 2;

border: 1px solid #000000;

border-top-color: #000000;

border-left-color: #000000;

border-right-color: #000000;

border-bottom-color: #000000;

background-color: #abcdef;

text-align: center;

cursor: hand;

}

</style>

<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; i<MaxStack; i++) {

Old_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<MaxStack; 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<MaxStack; 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<MaxStack; 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<MaxStack; 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"><img src="images/line_4.gif" width="60" height="15" class="inline"></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+=' <img src="images/line_4.gif" width="60" height="15" class="inline">';

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>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航