当前位置: 技术问答>java相关
请问各位大侠,如何构建一树型结构?
来源: 互联网 发布时间:2015-08-01
本文导语: 请问各位大侠,如何构建一树型结构?要求数据从数据库中取的!最好能用jsp或者javascript或者两者的结合。请各位大侠不吝赐教!(分数不够的话可以追加) | 下面有三个文件,稍作修改就可以...
请问各位大侠,如何构建一树型结构?要求数据从数据库中取的!最好能用jsp或者javascript或者两者的结合。请各位大侠不吝赐教!(分数不够的话可以追加)
|
下面有三个文件,稍作修改就可以了:
tree.jsp:
var Tree = new Array;
// nodeId | parentNodeId | nodeName | nodeUrl
tree.jsp:
var Tree = new Array;
// nodeId | parentNodeId | nodeName | nodeUrl
tree.js:
/**************************************************************************
Copyright (c) 2001 Geir Landrö (drop@destroydrop.com)
JavaScript Tree - www.destroydrop.com/hugi/javascript/tree/
Version 0.96
This script can be used freely as long as all copyright messages are
intact.
**************************************************************************/
// Arrays for nodes and icons
var nodes = new Array();;
var openNodes = new Array();
var icons = new Array(6);
// Loads all icons that are used in the tree
function preloadIcons() {
icons[0] = new Image();
icons[0].src = "img/plus.gif";
icons[1] = new Image();
icons[1].src = "img/plusbottom.gif";
icons[2] = new Image();
icons[2].src = "img/minus.gif";
icons[3] = new Image();
icons[3].src = "img/minusbottom.gif";
icons[4] = new Image();
icons[4].src = "img/folder.gif";
icons[5] = new Image();
icons[5].src = "img/folderopen.gif";
}
// Create the tree
function createTree(arrName, startNode, openNode) {
nodes = arrName;
if (nodes.length > 0) {
preloadIcons();
if (startNode == null) startNode = 0;
if (openNode != 0 || openNode != null) setOpenNodes(openNode);
if (startNode !=0) {
var nodeValues = nodes[getArrayId(startNode)].split("|");
document.write("" + nodeValues[2] + "");
} else document.write("Website");
var recursedNodes = new Array();
addNode(startNode, recursedNodes);
}
}
// Returns the position of a node in the array
function getArrayId(node) {
for (i=0; i