日期:2014-05-18  浏览次数:20406 次

求个解决思路关于树的。。。
请问怎么实现一棵树结构,包括在数据库中的存储,以及程序对树的处理,展现等操作,主要是在web应用方面。。。谢谢
谢绝控件。。。。。


顺便推广一下小弟的群5624113(200人,还有20多空)

------解决方案--------------------
存储过程+JS.如有需要跟我联系
------解决方案--------------------
参考CDSDN左边的树
------解决方案--------------------
function TreeView(obj,target){
this.obj=obj;
this.target= 'right ';
this.root=new node(0);
this.nodes=[]
this.currentNode=null;
this.html= " "
this.config={
root : 'images/tree/web.gif ',
open : 'images/tree/open.gif ',
close : 'images/tree/close.gif ',
file : 'images/tree/file.gif ',
join : 'images/tree/T.gif ',
joinbottom : 'images/tree/L.gif ',
plus : 'images/tree/Tplus.gif ',
plusbottom : 'images/tree/Lplus.gif ',
minus : 'images/tree/Tminus.gif ',
minusbottom : 'images/tree/Lminus.gif ',
blank : 'images/tree/empty.gif ',
line : 'images/tree/dd.gif '
}
for(i in this.config){var tem=this.config[i];this.config[i]=new Image();this.config[i].src=tem}
}

function node(id,pid,txt,link,title,target){
this.id=id
this.pid=pid
this.txt=txt
this.link=link
this.title=title
this.target=target
this.indent= " "
this.lastNode=false;
this.open=false;
this.hasNode=false
}

TreeView.prototype.getP=function(nid){
var nNode=this.nodes[nid]
for(var i=0;i <this.nodes.length;i++)
if(this.nodes[i].id==nNode.pid)return i
return null
}

TreeView.prototype.add=function(id,pid,txt,link,title,target){
var itemTxt=txt?txt: "New Item "
var itemLink=link?link: ' '
var itemTitle=title?title:itemTxt;
var itemTarget=target?target:this.target;
this.nodes[this.nodes.length]=new node(id,pid,itemTxt,itemLink,itemTitle,itemTarget)
pid==this.root.id?this.nodes[this.nodes.length-1].open=true: ' '
}

TreeView.prototype.DrawTree=function(pNode){
var str= " "
for(var i=0;i <this.nodes.length;i++){
if(this.nodes[i].pid==pNode.id){
str+=this.DrawNode(i)
}
}
return str
}

TreeView.prototype.ChkPro=function(pNode){
var last;
for(var n=0;n <this.nodes.length;n++){
if(this.nodes[n].pid==pNode.id)pNode.hasNode=true;
if (this.nodes[n].pid == pNode.pid) last= this.nodes[n].id;
}
if (last==pNode.id) pNode.lastNode = true;
}

TreeView.prototype.DrawNode=function(nid){
var str= " "
var nNode=this.nodes[nid]
this.DrawLine(nNode,nNode)
if(nNode.hasNode)
nNode.indent+= " <a href= '# ' onclick= ' "+this.obj+ ".Click( "+nid+ ",this);return(false) '> "
nNode.indent+=this.root.id!=nNode.pid?( " <img align= 'absmiddle ' src= ' "+(nNode.lastNode?(nNode.hasNode?this.config.plusbottom.src:this.config.joinbottom.src):(nNode.hasNode?this.config.plus.src:this.config.join.src))+ " ' id= 'icon "+this.obj+nid+ " ' border=0> "): " "
nNode.indent+= " <img id= 'folder "+this.obj+nid+ " ' align= 'absmiddle ' src= ' "+(nNode.pid==this.root.id?this.config.root.src:(nNode.hasNode?(nNode.open?this.config.open.src:this.config.close.src):this.config.file.src))+ " ' border=0> "+(nNode.hasNode? " </a> ": " &quo