递归显示部门

来源:互联网 发布:andriod连接mac电脑 编辑:程序博客网 时间:2024/05/16 11:44

<script>
function menuFoldClick(){
var srcE=window.event.srcElement;
var tagName=window.event.srcElement.tagName;
if(tagName=="LI"){
var nextBrother=srcE.nextSibling;
if(nextBrother.nodeType!=1){
nextBrother=nextBrother.nextSibling;
}
if(nextBrother.tagName=="UL"){
var displayCss=nextBrother.style.display;
if(displayCss=="none"){
nextBrother.style.display="";
}else{
nextBrother.style.display="none";
}
}
}
}
</script>



<ul onclick="menuFoldClick()">

<%HashMap depMap=(HashMap)request.getAttribute("depMap"); %>
<%!public void printSubDep(JspWriter out,HashMap depMap,Integer j,Integer id){
List list2=(List)depMap.get(j);
if(list2!=null&&list2.size()>0){
try{
boolean flag=false;
for(int n=0;n<list2.size();n++){
TDepartment dep2 =(TDepartment)list2.get(n);
if(dep2.getUpDep().intValue()==id.intValue()){
flag=true;
break;
}
}
if(flag) out.print("<ul>");
int k=j;
for(int n=0;n<list2.size();n++){
TDepartment dep2 =(TDepartment)list2.get(n);
if(dep2.getUpDep().intValue()==id.intValue()){
out.print("<li>" + dep2.getDepName()
+ "</li>");
j++;
printSubDep(out,depMap,j,dep2.getId());
}
j=k;
}
if(flag) out.print("</ul>");
}catch(IOException e){
e.getStackTrace();
}
}
} %>
<%
if (depMap.size()>0) {
List depListObj = (List) depMap.get(1);
for (int j = 0; j < depListObj.size(); j++) {
TDepartment dep = (TDepartment) depListObj.get(j);
out.print("<li>" + dep.getDepName() + "</li>");
printSubDep(out,depMap,2,dep.getId());
}
}
%>
</ul>
0 0