代码改变世界

对于树状结构

2006-11-14 20:44  迷路中的路人甲  阅读(280)  评论(1编辑  收藏  举报
树结构就不说了。说一下树中其他的字段。
Level :可以用来判断当前节点的等级,这样生成树的时候,可以计算它的缩进位置。
isForder:用来判断当前节点是否有子节点。用来判断节点前面的图标。
操作的时候,一般利用ajax方式根据当前节点的ID,读取所有下级子节点,生成XML文件。包含节点信息。
用js操作,生成节点信息。
附加一些操作代码:
        function checkXML(request)
        
{
            
var xmlDoc=request.responseXML;
            success
=xmlDoc.getElementsByTagName("success");
            
            
if(success[0].childNodes[0].nodeValue=="true")
            
{
                
var pid=xmlDoc.getElementsByTagName("nodetype")[0].childNodes[0].text;
                
var oldid=xmlDoc.getElementsByTagName("oldid")[0].childNodes[0].text;
                
var y = xmlDoc.getElementsByTagName("leaf");

                
                
for(i=0;i<y.length;i++)
                
{
                    id
=y[i].childNodes[0].text;
                    level
=y[i].childNodes[1].text;
                    name
=unescape(y[i].childNodes[2].text);
                    depart
=unescape(y[i].childNodes[3].text);
                    duty
=unescape(y[i].childNodes[4].text);
                    isforder
=y[i].childNodes[5].text;
                    
var x;
                    
var l1="";
                
                    
for(x=0;x<parseInt(level);x++)
                    
{
                        l1
+="<span style='vertical-align: middle; font-size: 21px; height: 20px; color: #D4D0C8; cursor: default'>│</span>";
                    }

                    
if(i==y.length-1)
                    
{
                        l1
+="<span style='vertical-align: middle; font-size: 21px; height: 20px; color: #D4D0C8; cursor: default'>└</span>";
                    }

                    
else
                    
{
                        l1
+="<span style='vertical-align: middle; font-size: 21px; height: 20px; color: #D4D0C8; cursor: default'>├</span>";
                    }

                    
                    
var img;
                    
if(parseInt(isforder)==1)
                    
{
                        img      
= "<img width=16 height=16 src=\"/icon/folder.gif\" align=\"absmiddle\" border=0 style=\"cursor:hand;\" onclick=\"getChild('"+id+"_"+level+"','"+id+"');\"/> ";
                    }

                    
else
                    
{
                        img      
= "<img width=16 height=16 src=\"/icon/file.gif\" align=\"absmiddle\" border=0/> "
                    }

                    
var newnode=document.createElement("div");
                    newnode.setAttribute(
"id",id +"_" + level)
                    newnode.setAttribute(
"onclick","getChild('"+id+"_"+level+"','"+id+"');");
                    newnode.setAttribute(
"style","height:20px;padding:0px;margin:0px;border:solid 1px #eee;display:block;");
                    $(pid).appendChild(newnode);
                    
                    
var childE=document.createElement("span");
                    childE.setAttribute(
"id",id);
                    $(pid).appendChild(childE);    
                    
                    newnode.innerHTML
= l1 + img +"<a href='/datereport/reportlist.aspx?userid="+id+"'>" + name + "("+depart+"_"+duty+")</a>";
                    
                }

                Element.hide(
"alertmessage");
            }

        }