根據(jù)ID、父ID來(lái)排序的JS樹(shù)
// 得到接點(diǎn)
var datas = sFileName.selectNodes("datas/data") ;
var list = new Array() ;
var data = new Array() ;
for( var i = 0 ; i < datas.length ; i++ ){
if( datas[i].getAttribute( "類型" ) == "文件夾" ){
list.push( datas[i] ) ;
} else {
data.push( datas[i] ) ;
}
}
// 設(shè)置初始的父號(hào)
var fatherNo = -1 ;
// 顯示目錄
showTreeList( tree , fatherNo , datas ,list , data , null ,"") ;
// 改變圖片和隱藏顯示DIV
function expand( div , img ){
if( div.style.display == "block" ){
div.style.display = "none" ;
img.src = "images/pic/skin_NLine/closed.gif" ;
} else {
div.style.display = "block" ;
img.src = "http://blog.itpub.net/13428095/viewspace-1000879/images/pic/skin_NLine/opened.gif" ;
}
}
// 遞歸顯示樹(shù)
function showTreeList( tree , fatherNo , datas ,list , data , currentNode , listStrblank2 ) {
// 創(chuàng)建一個(gè)DIV
var treediv = document.createElement("div");
var isdisplay = "1" //節(jié)點(diǎn)的狀態(tài) 默認(rèn)為顯示狀態(tài)
treediv.id = "treediv" + isdisplay + fatherNo ;
if( currentNode ){
tree.innerHTML += listStrblank2 + "" + currentNode.getAttribute( "組名稱" ) + "
" ;
}
treediv.style.display = "block";
document.getElementById("MonitorObject").appendChild( treediv );
// 如果currentNode存在則顯示組名稱
var l = isChildList( fatherNo , list ) ;
// 如果有子目錄,則在次循環(huán).沒(méi)有則判斷是否有信息
if( l.length != 0 ){
listStrblank2 += " " ;
for( var j = 0 ; j < l.length ; j++ ){
showTreeList( treediv , l[j].getAttribute( "id" ) , datas ,list , data , l[j] , listStrblank2 ) ;
}
}
var d = isChildData( fatherNo , data ) ;
// 如果有子信息,則在次循環(huán).沒(méi)有則判斷是否有信息
if( d.length != 0 ){
for( var j = 0 ; j < d.length ; j++ ) {
treediv.innerHTML += listStrblank2 + "" + "美女" + "
" ;
}
}
tree.appendChild(treediv) ;
}
// 判斷是否有子文件夾
function isChildList( fatherNo , lists ){
// 定義一個(gè)保存子目錄的對(duì)象
var l = new Array() ;
// 循環(huán)找其子目錄
for( var i = 0 ; i < lists.length ; i++ ) {
// 如果父編號(hào)和父號(hào)相同,則保存
if( lists[i].getAttribute( "父編號(hào)" ) == fatherNo ) {
l.push( lists[i] ) ;
}
}
return l ;
}
// 判斷是否有子信息
function isChildData( fatherNo , datas ){
var d = new Array() ;
for( var i = 0 ; i < datas.length ; i++ ) {
if( datas[i].getAttribute( "父編號(hào)" ) == fatherNo ) {
d.push( datas[i] ) ;
//alert(datas[i].getAttribute( "對(duì)象屬性" )) ;
}
}
return d ;
}
[@more@]
網(wǎng)站題目:根據(jù)ID、父ID來(lái)排序的JS樹(shù)
文章鏈接:
http://weahome.cn/article/jiojcg.html