当前位置: 技术问答>java相关
高手请指教,jsp和javascript和数据库联合动态生成树型结构,怎么实现呢????(在线等待给100分)
来源: 互联网 发布时间:2015-08-13
本文导语: 我从数据库中读出结果集,我不知道怎么很树型结构联合起来, 例如: 数据库字段: id,parentid 树型结构: 我不知道jsp 和javascript 怎么联合 tree.jsp xg_delayth's Tree function xg_TreeNode(ANodeID,ANodeInnerHtml,AN...
我从数据库中读出结果集,我不知道怎么很树型结构联合起来,
例如:
数据库字段:
id,parentid
树型结构:
我不知道jsp 和javascript 怎么联合
tree.jsp
xg_delayth's Tree
function xg_TreeNode(ANodeID,ANodeInnerHtml,ANodeParentID,ANodeDivID){
this.nodeID=ANodeID;
this.nodeInnerHtml=ANodeInnerHtml;
this.nodeParentID=ANodeParentID;
this.nodeDivID=ANodeDivID;
//-- if 0 not view the children else if 1 view the children
this.nodeIsView=0;
}
function xg_Tree(){
//-- store the information about the tree
this.xg_TreeArray=new Array();
//-- create the root node
this.xg_TreeArray[0]=new xg_TreeNode(0,"组群管理",-1,"xgDiv0");
//-- store the tree_node number
this.xg_ArrayCount=1;
this.xg_TreeInsert=xg_TreeInsert;
this.xg_TreeSearch=xg_TreeSearch;
this.xg_TreeDelete=xg_TreeDelete;
this.xg_GetNodeCount=xg_GetNodeCount;
}
function xg_TreeInsert(ATreeNode){
with(this){
//-- if ATreeNode is null or it's parentid is null or it's id had been in tree return -1;
if (!ATreeNode || ""==xg_TreeSearch(this,ATreeNode.nodeParentID) || ""!=xg_TreeSearch(this,ATreeNode.nodeID)){
return -1;
}
xg_TreeArray[xg_ArrayCount]=ATreeNode;
xg_ArrayCount++;
}
}
function xg_TreeSearch(AXGTree,ANodeID){
with(AXGTree){
for (var i=0;i
======================
caidan.jsp:修改一下就OK了
==================
→
例如:
数据库字段:
id,parentid
树型结构:
我不知道jsp 和javascript 怎么联合
tree.jsp
xg_delayth's Tree
function xg_TreeNode(ANodeID,ANodeInnerHtml,ANodeParentID,ANodeDivID){
this.nodeID=ANodeID;
this.nodeInnerHtml=ANodeInnerHtml;
this.nodeParentID=ANodeParentID;
this.nodeDivID=ANodeDivID;
//-- if 0 not view the children else if 1 view the children
this.nodeIsView=0;
}
function xg_Tree(){
//-- store the information about the tree
this.xg_TreeArray=new Array();
//-- create the root node
this.xg_TreeArray[0]=new xg_TreeNode(0,"组群管理",-1,"xgDiv0");
//-- store the tree_node number
this.xg_ArrayCount=1;
this.xg_TreeInsert=xg_TreeInsert;
this.xg_TreeSearch=xg_TreeSearch;
this.xg_TreeDelete=xg_TreeDelete;
this.xg_GetNodeCount=xg_GetNodeCount;
}
function xg_TreeInsert(ATreeNode){
with(this){
//-- if ATreeNode is null or it's parentid is null or it's id had been in tree return -1;
if (!ATreeNode || ""==xg_TreeSearch(this,ATreeNode.nodeParentID) || ""!=xg_TreeSearch(this,ATreeNode.nodeID)){
return -1;
}
xg_TreeArray[xg_ArrayCount]=ATreeNode;
xg_ArrayCount++;
}
}
function xg_TreeSearch(AXGTree,ANodeID){
with(AXGTree){
for (var i=0;i
======================
caidan.jsp:修改一下就OK了
==================
→
====================
|
试把你的区代码改成这样
var xgTree=new xg_Tree();
var xgTreeNode=new xg_TreeNode(,"",,"xgDiv"+(i+1));
xgTree.xg_TreeInsert(xgTreeNode);
var xgTree=new xg_Tree();
var xgTreeNode=new xg_TreeNode(,"",,"xgDiv"+(i+1));
xgTree.xg_TreeInsert(xgTreeNode);
divID.innerHTML=xg_ShowTree(xgTree);
eval(xgTree.xg_TreeArray[0].nodeDivID+".style.display='inline';");
应该可以了,但是你用int[] id=new int[10];来做循环,当记录超过10条就会出错,应该现count数据库的记录条数,然后用这个条数for循环就没问题了