日期:2014-05-16  浏览次数:20345 次

烦人的js XTree 动态组装数据问题

<script type="text/javascript">
???
function subproject(id,pid,name){//定义一js对象
?this.id=id;
?this.pid=pid;
?this.name=name;
?
}

subproject.prototype.toString=function(){//定义对象一方法
?//alert("name===>"+this.name+" id===>"+this.id+"? pid=>"+this.pid);
}?

var demo=new Array();//定义一数组,以下为系列数据

?var project=new subproject
??(
???'12343',
???'200907301526500312',
???'0909'
??);
?demo.push(project);

?var project=new subproject
??(
???'2009072918252412343',
???'12343',
???'090901'
??);
?demo.push(project);

?var project=new subproject
??(
???'200907301526500311',
???'12343',
???'da'
??);
?demo.push(project);

?var project=new subproject
??(
???'200908101134525701',
???'200907301526500311',
???'da1.1'
??);
?demo.push(project);

?var project=new subproject
??(
???'200908061536315461',
???'12343',
???'testDWR insert a node '
??);
?demo.push(project);

?var project=new subproject
??(
???'200908031628512851',
???'200907301526500312',
???'分解子项目测试'
??);
?demo.push(project);

?var project=new subproject
??(
???'200908031635374261',
???'200908031628512851',
???'分解子项目测试修改之再分'
??);
?demo.push(project);

?var project=new subproject
??(
???'200908031639480511',
???'200908031628512851',
???'分解子项目测试之一'
??);
?demo.push(project);

?var project=new subproject
??(
???'200908101132502741',
???'200908031639480511',
???'分解子项目测试之一1'
??);
?demo.push(project);

?var project=new subproject
??(
???'200908101132502581',
???'200908031639480511',
???'分解子项目测试之一1'
??);
?demo.push(project);

?var project=new subproject
??(
???'200908101132502891',
???'200908031639480511',
???'分解子项目测试之一1'
??);
?demo.push(project);

?var project=new subproject
??(
???'200908031640121761',
???'200908031628512851',
???'分解子项目测试OK'
??);
?demo.push(project);

?var project=new subproject
??(
???'200908031640255041',
???'200908031640121761',
???'分解子项目测试OK1'
??);
?demo.push(project);

?

?

?

??
if (document.getElementById) {//以下开始组装数据
?var tree = new WebFXTree('东明大道(广深高速-光明园区宝安段)工程',"javaScript:showDiv(this,'200907301526500312','-1');");
?tree.setBehavior('classic');
//new WebFXTreeItem([text], [action], [parent], [icon], [openIcon])
?// 可以在任何地方调用add方法加入子节点。
for(var i=0;i<demo.length;i++){
?var bean=demo[i];
?
?var a =new WebFXTreeItem(bean.name,'200907301526500312');//tree root

if(bean.pid=='200907301526500312'){
?tree.add(a);
?}

?//寻子节点
?for(var j=1;j<demo.length;j++){
??var sub=demo[j];
??
??if(bean.id==sub.pid){
???var b =new WebFXTreeItem(sub.name,"javaScript:showDiv(this"+",'"+sub.id+"','"+sub.pid+"');");
???a.add(b);
???//迭归寻出子节点下面的子节点
???//demo.addNode(sub);
??}?
}???
}

//实际
?document.write(tree);
}