- 浏览: 189430 次
- 性别:
- 来自: 深圳
最新评论
-
shis_y:
那是你的localhost或者web服务器的80端口被占用或者 ...
通过虚拟地址解决fckeditor错误的加载/fckeditor/fckstyles.xml -
forcer521:
com.gemt.dataswap.util.Constant ...
使用DES算法进行加密和解密 -
ngn9999:
dTree确实不错,这是我的使用经验: http://www. ...
javascript树型菜单(Dtree和Xtree) -
yueliangwolf:
这个dhtmlxtree.js里面有enableSmartXM ...
使用xml或者json方式生成dhtmlxtree -
yanMouse:
谢谢,能否有个联系方式,我现在也在看这方面的东西
dhtmlxtree的一个实用demo
1. dao
private static ParameterizedRowMapper<MenuInfo> menuInfoMapper = new ParameterizedRowMapper<MenuInfo>() {
public MenuInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
MenuInfo menuInfo = new MenuInfo();
menuInfo.setHasit(rs.getString("hasit"));
menuInfo.setPmenuid(rs.getLong("pmenuid"));
menuInfo.setLevel(rs.getLong("level"));
menuInfo.setId(rs.getLong("id"));
menuInfo.setMsrtno(rs.getLong("msrtno"));
menuInfo.setMenunm(rs.getString("menunm"));
menuInfo.setLocation(rs.getString("location"));
menuInfo.setActiontyp(rs.getLong("actiontyp"));
menuInfo.setHlpid(rs.getLong("hlpid"));
menuInfo.setLfabl(rs.getString("lfabl"));
menuInfo.setFbdst(rs.getString("fbdst"));
return menuInfo;
}
};
public Collection<MenuInfo> testPrivilege() {
final String sql = "select nvl((select 'a' from wpv0105_rlprv b where b.lbl='0' and b.rlid=? and b.prvid=a.id),'b') as hasit, "
+" a.pmenuid,level, a.id, a.msrtno, a.menunm, a.location, a.actiontyp, a.hlpid, a.lfabl,a.fbdst "
+" from wpv0101_menu a start with pmenuid=-1 connect by prior id = pmenuid and a.id<>100031401 "
+" group by pmenuid,level, id, msrtno, menunm, location, actiontyp, hlpid, lfabl,fbdst "
+" order by id||'0', msrtno";
return jdbcTemplate.query(sql, menuInfoMapper, new Object[]{new Long(0)});
}
2. 数据封装
(1) xml
@Test public void testMenu() throws Exception {
java.util.Collection<MenuInfo> menuInfoList = mobileDao.testPrivilege();
java.io.OutputStream out = null;
java.io.OutputStreamWriter dataout = null;
out = new java.io.FileOutputStream("aaa.xml");
dataout = new java.io.OutputStreamWriter(out, "UTF-8");
dataout.write("<?xml version='1.0' encoding='UTF-8'?>\n<tree id='0'>");
int level=0;
for(MenuInfo vo : menuInfoList)
{
if(level == Integer.parseInt(vo.getLevel()+"")) {
dataout.write("</item>\r\n");
final String chk = "a".equals(vo.getHasit())?"checked=\"1\"":"";
dataout.write("<item " + chk + " text=\""+ vo.getMenunm() +"\" id=\"" + vo.getId() + "\" im0=\"leaf.gif\" im1=\"folderOpen.gif\" im2=\"folderClosed.gif\">");
}
else if(Integer.parseInt(vo.getLevel()+"") > level) {
final String chk = "a".equals(vo.getHasit())?"checked=\"1\"":"";
dataout.write(" <item " + chk + " text=\""+ vo.getMenunm() +"\" id=\"" + vo.getId() + "\" im0=\"leaf.gif\" im1=\"folderOpen.gif\" im2=\"folderClosed.gif\">");
}
else {
for(int i =0; i < level + 1 - Integer.parseInt(vo.getLevel()+""); i++)
dataout.append("</item>\r\n");
final String chk = "a".equals(vo.getHasit())?"checked=\"1\"":"";
dataout.write("<item " + chk + " text=\""+ vo.getMenunm() +"\" id=\"" + vo.getId() + "\" im0=\"leaf.gif\" im1=\"folderOpen.gif\" im2=\"folderClosed.gif\">");
}
level = Integer.parseInt(vo.getLevel()+"");
}
for(int j =0; j <level; j++)
dataout.write("</item>\r\n");
dataout.write("</tree>");
dataout.flush();
dataout.close();
out.close();
}
(2) json
@Test public void testMenuJSON() throws Exception {
java.util.Collection<MenuInfo> menuInfoList = mobileDao.testPrivilege();
java.io.OutputStream out = null;
java.io.OutputStreamWriter dataout = null;
out = new java.io.FileOutputStream("bbb.JSON");
dataout = new java.io.OutputStreamWriter(out, "UTF-8");
dataout.write("{id:'0' ");
int level=0;
for(MenuInfo vo : menuInfoList)
{
if(level == Integer.parseInt(vo.getLevel()+"")) {
dataout.write("}\r\n");
final String chk = "a".equals(vo.getHasit())?"checked:'1', ":"";
dataout.write(",{" + "id:'" + vo.getId()+ "', " + chk + "text:'"+ vo.getMenunm() + "', im0:'leaf.gif', im1:'folderOpen.gif', im2:'folderClosed.gif'");
}
else if(Integer.parseInt(vo.getLevel()+"") > level) {
final String chk = "a".equals(vo.getHasit())?"checked:'1', ":"";
dataout.write(", item:[{" + "id:'" + vo.getId()+ "', " + chk + "text:'"+ vo.getMenunm() + "', im0:'leaf.gif', im1:'folderOpen.gif', im2:'folderClosed.gif'");
}
else {
for(int i =0; i < level - Integer.parseInt(vo.getLevel()+""); i++)
dataout.append("}\r\n]\r\n");
final String chk = "a".equals(vo.getHasit())?"checked:'1', ":"";
dataout.write("}\r\n,{" + "id:'" + vo.getId()+ "', " + chk + "text:'"+ vo.getMenunm() + "', im0:'leaf.gif', im1:'folderOpen.gif', im2:'folderClosed.gif'");
}
level = Integer.parseInt(vo.getLevel()+"");
}
for(int j =0; j <level; j++)
dataout.write("}]\r\n");
dataout.write("}");
dataout.flush();
dataout.close();
out.close();
}
3. 我对比了一下,若不使用专业版的dhtmltree的情况下,都加载大数据,使用xml和json的速度一样慢,几乎没有区别。主要还是渲染生成树的计算太复杂,若使用专业版(太贵了,都要800多美元),并把它的 tree.enableSmartXMLParsing(true) 因为它在你查看该节点时才加载它的子节点,所以树能很快显示,它还有一点做的特别好就是在树的有些节点没有被加载的情况下,通过tree.getAllChecked()也能够获取到这些节点。
private static ParameterizedRowMapper<MenuInfo> menuInfoMapper = new ParameterizedRowMapper<MenuInfo>() {
public MenuInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
MenuInfo menuInfo = new MenuInfo();
menuInfo.setHasit(rs.getString("hasit"));
menuInfo.setPmenuid(rs.getLong("pmenuid"));
menuInfo.setLevel(rs.getLong("level"));
menuInfo.setId(rs.getLong("id"));
menuInfo.setMsrtno(rs.getLong("msrtno"));
menuInfo.setMenunm(rs.getString("menunm"));
menuInfo.setLocation(rs.getString("location"));
menuInfo.setActiontyp(rs.getLong("actiontyp"));
menuInfo.setHlpid(rs.getLong("hlpid"));
menuInfo.setLfabl(rs.getString("lfabl"));
menuInfo.setFbdst(rs.getString("fbdst"));
return menuInfo;
}
};
public Collection<MenuInfo> testPrivilege() {
final String sql = "select nvl((select 'a' from wpv0105_rlprv b where b.lbl='0' and b.rlid=? and b.prvid=a.id),'b') as hasit, "
+" a.pmenuid,level, a.id, a.msrtno, a.menunm, a.location, a.actiontyp, a.hlpid, a.lfabl,a.fbdst "
+" from wpv0101_menu a start with pmenuid=-1 connect by prior id = pmenuid and a.id<>100031401 "
+" group by pmenuid,level, id, msrtno, menunm, location, actiontyp, hlpid, lfabl,fbdst "
+" order by id||'0', msrtno";
return jdbcTemplate.query(sql, menuInfoMapper, new Object[]{new Long(0)});
}
2. 数据封装
(1) xml
@Test public void testMenu() throws Exception {
java.util.Collection<MenuInfo> menuInfoList = mobileDao.testPrivilege();
java.io.OutputStream out = null;
java.io.OutputStreamWriter dataout = null;
out = new java.io.FileOutputStream("aaa.xml");
dataout = new java.io.OutputStreamWriter(out, "UTF-8");
dataout.write("<?xml version='1.0' encoding='UTF-8'?>\n<tree id='0'>");
int level=0;
for(MenuInfo vo : menuInfoList)
{
if(level == Integer.parseInt(vo.getLevel()+"")) {
dataout.write("</item>\r\n");
final String chk = "a".equals(vo.getHasit())?"checked=\"1\"":"";
dataout.write("<item " + chk + " text=\""+ vo.getMenunm() +"\" id=\"" + vo.getId() + "\" im0=\"leaf.gif\" im1=\"folderOpen.gif\" im2=\"folderClosed.gif\">");
}
else if(Integer.parseInt(vo.getLevel()+"") > level) {
final String chk = "a".equals(vo.getHasit())?"checked=\"1\"":"";
dataout.write(" <item " + chk + " text=\""+ vo.getMenunm() +"\" id=\"" + vo.getId() + "\" im0=\"leaf.gif\" im1=\"folderOpen.gif\" im2=\"folderClosed.gif\">");
}
else {
for(int i =0; i < level + 1 - Integer.parseInt(vo.getLevel()+""); i++)
dataout.append("</item>\r\n");
final String chk = "a".equals(vo.getHasit())?"checked=\"1\"":"";
dataout.write("<item " + chk + " text=\""+ vo.getMenunm() +"\" id=\"" + vo.getId() + "\" im0=\"leaf.gif\" im1=\"folderOpen.gif\" im2=\"folderClosed.gif\">");
}
level = Integer.parseInt(vo.getLevel()+"");
}
for(int j =0; j <level; j++)
dataout.write("</item>\r\n");
dataout.write("</tree>");
dataout.flush();
dataout.close();
out.close();
}
(2) json
@Test public void testMenuJSON() throws Exception {
java.util.Collection<MenuInfo> menuInfoList = mobileDao.testPrivilege();
java.io.OutputStream out = null;
java.io.OutputStreamWriter dataout = null;
out = new java.io.FileOutputStream("bbb.JSON");
dataout = new java.io.OutputStreamWriter(out, "UTF-8");
dataout.write("{id:'0' ");
int level=0;
for(MenuInfo vo : menuInfoList)
{
if(level == Integer.parseInt(vo.getLevel()+"")) {
dataout.write("}\r\n");
final String chk = "a".equals(vo.getHasit())?"checked:'1', ":"";
dataout.write(",{" + "id:'" + vo.getId()+ "', " + chk + "text:'"+ vo.getMenunm() + "', im0:'leaf.gif', im1:'folderOpen.gif', im2:'folderClosed.gif'");
}
else if(Integer.parseInt(vo.getLevel()+"") > level) {
final String chk = "a".equals(vo.getHasit())?"checked:'1', ":"";
dataout.write(", item:[{" + "id:'" + vo.getId()+ "', " + chk + "text:'"+ vo.getMenunm() + "', im0:'leaf.gif', im1:'folderOpen.gif', im2:'folderClosed.gif'");
}
else {
for(int i =0; i < level - Integer.parseInt(vo.getLevel()+""); i++)
dataout.append("}\r\n]\r\n");
final String chk = "a".equals(vo.getHasit())?"checked:'1', ":"";
dataout.write("}\r\n,{" + "id:'" + vo.getId()+ "', " + chk + "text:'"+ vo.getMenunm() + "', im0:'leaf.gif', im1:'folderOpen.gif', im2:'folderClosed.gif'");
}
level = Integer.parseInt(vo.getLevel()+"");
}
for(int j =0; j <level; j++)
dataout.write("}]\r\n");
dataout.write("}");
dataout.flush();
dataout.close();
out.close();
}
3. 我对比了一下,若不使用专业版的dhtmltree的情况下,都加载大数据,使用xml和json的速度一样慢,几乎没有区别。主要还是渲染生成树的计算太复杂,若使用专业版(太贵了,都要800多美元),并把它的 tree.enableSmartXMLParsing(true) 因为它在你查看该节点时才加载它的子节点,所以树能很快显示,它还有一点做的特别好就是在树的有些节点没有被加载的情况下,通过tree.getAllChecked()也能够获取到这些节点。
- b.rar (114.3 KB)
- 下载次数: 487
评论
2 楼
yueliangwolf
2010-07-12
这个dhtmlxtree.js里面有enableSmartXMLParsing(true)这个方法吗?有的话发我一个,找了好多,都没有这个方法...
1 楼
filix
2009-02-07
谢谢分享!看了真是豁然开朗!
发表评论
-
kdb+/q
2008-11-28 20:13 1876因为一个项目接触了kdb+/q, kdb+/q的执行速度应该 ... -
seam随笔
2008-09-28 20:33 1182前段时间,因为客户的一个项目接触了seam,客户那边在 ... -
richfaces换肤
2008-08-27 23:18 0http://leonardinius.blogspot.co ... -
jfree chart...
2008-08-17 11:38 0see attachment. -
crystal report
2008-08-04 21:57 0crystal report http://oceang-y. ... -
js code example
2008-07-01 16:25 0<html> <body> <s ... -
dhtmlgoodies网站上的一些js,也许在工作中用得到
2008-06-23 16:28 1498到http://www.dhtmlgoodies.com ... -
Hibernate的一个例子
2008-05-31 23:32 1056通过hibernate tools的反向工程从数据库产生ent ... -
在cxf基础上整的一个框架
2008-04-24 08:48 1070使用cxf作为webservice的服务器,以spring b ... -
S60签名
2008-04-16 17:14 1483前段时间写了一个程序,放到S60第三版的手机系统上面老是报权限 ... -
socket消息超时重发的设想
2008-04-08 17:00 4028我们经常遇到的一个问题就是:发送一条消息,若在T秒内没有 ... -
io,nio和操作系统命令性能比较
2008-03-31 20:50 2232package org.clarance; import j ... -
要开始做一个网络的项目了
2008-03-27 22:38 1292一个在线环境监测的项目, 监控中心用java编写,接受现 ... -
使用jQuery解决portal登陆慢的问题
2007-12-19 16:58 2236因为portal中的好几块地方(portlet)取数据比较慢, ... -
使用javascript遍历XML文件并显示
2007-12-10 17:11 6638以下代码在IE和Firefox上测试通过: <html& ... -
JSON技术实战
2007-12-07 09:23 11016JSON作为一种信息的载体 ... -
使用HttpClient对web应用进行测试
2007-11-29 16:19 2934在几天程序突然报出了数据库连接被管理员销毁的情况! 一时之间也 ... -
判断日期是否有效的正则表达式
2007-09-10 17:59 1206function isValidDate(dateStr, f ... -
取oracle的error code
2007-08-30 15:39 2792有时候需要知道oracle的error code的具体含义, ... -
JFreeChart生成图片并显示
2007-08-28 09:51 2984源代码在附件中, 部署到sevlet容器中, 通过URL访问s ...
相关推荐
圣诞节到了,我为大家送上java版的纯json数据构建树的demo,嘻嘻有了这个demo想建多少棵圣诞树也不是问题!送给各位位辛勤劳动的软件工程师们,祝大家圣诞快乐,新年快乐!身体健康,事业有成哦!
通过开发一个小工具讲述DHtmlXTree的应该 主要内容: DHtmlXTree生成设置 xml文档生成 DHtmlXTree加载xml文档
dhtmlxTree代码,通过加载后台XML组建树结构,前台使用JS加载
dhtmlXtree树 右dhtmlXtree键菜单
可将目录生成dhtmlxTree可识别的xml文件,xml文件可直接被dhtmlx读取加载!
dhtmlxtree和json的应用。自己写的练习项目,免费下载。
DHTMLX 使用手冊版本 (Version):2.0.0 dhtmlxLayout是一个 JavaScript的DHTML的 组成部分,它提供了强大而有效的方式来建立 Ajax的Web界面 轻松。 该组件允许您以编程定义界面结构,包括大小元素及其布局。 最终...
专业版dhtmlxtree下载 专业版dhtmlxtree下载
NULL 博文链接:https://shoushounihao.iteye.com/blog/1775589
dhtmlxtree例子
DHtmlXTree 调用xml http://blog.csdn.net/ymc0329/article/details/6619796
dhtmlxtree中文开发指导,简单介绍dhtmlxtree的使用。初学者适合。
简单的Dhtmlxtree的运用,树是通过xml加载成的。
包含dhtmlxTree(树型控件),dhtmlxTabbar(选项卡),dhtmlxGrid(数据表格),dhtmlxCombo(下拉选项),dhtmlxTreeGrid(树型表格),dhtmlxVault(文件上传控件),dhtmlxMenu(菜单),dhtmlxToolbar(工具条),dhtmlxCalendar(日历...