MyException - 我的异常网
当前位置:我的异常网» Java Web开发 » 如何用梅花雪树形控件从数据库动态显示

如何用梅花雪树形控件从数据库动态显示(2)

www.MyException.Cn  网友分享于:2013-12-20  浏览:63次

tree.icons[ "book "] = "book.gif ";
tree.iconsExpand[ "book "] = "bookopen.gif "; //展开时对应的图片
tree.setIconPath( "/WebModule1/IMG/ "); //可用相对路径
<%
String tree = t.getTree();
out.print(tree);
%>
document.write(tree.toString()); //亦可用 obj.innerHTML = tree.toString();
</script>
<body bgcolor= "#ffffff ">
<input type=button value=展开所有节点 onclick= "tree.expandAll() ">
<br/>
</body>
</html>
下面是调用的Bean
package tree;

import java.sql.*;

public class tree {
public tree() {
}

public String getTree() {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
jdbc j = new jdbc();
con = j.getcon();
String sql = "select * from tree order by id ";
String tree = " ";
try {
pstmt = con.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next()) {
String id = String.valueOf(rs.getInt( "id "));
String pid = String.valueOf(rs.getInt( "parent_id "));
String text = rs.getString( "text ");
tree += "\ntree.nodes[\ " " + pid + "_ " + id + "\ "]=\ " ";
if (text != null && text.trim() != " ") {
tree += "text: " + text + "; ";
}
tree += "\ " ";
}
} catch (SQLException ex) {
ex.printStackTrace();
}
System.out.println(tree);
return tree;
}
}
数据库表字段是 id(自增) parent_id text

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有