微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jquery中EasyUI实现异步树

前台使用EasyUI实现 . EasyUI向后台传递一个id参数 .

第一次加载,向后台传递的id为null .

之后每次将树节点展开,会向后台传递一个当前节点的 id .

Control层 :

代码如下:

Service层 :

代码如下:
getChildrenTree(String pid) { try { List result = new ArrayList(); //获得儿子节点的列表 List childrenList = this.getChildrenType(pid); if (childrenList != null && childrenList.size() > 0) { for (TBookType child : childrenList) { // 获取孙子的个数 long count = bookDao.getChildrenCount(String.valueOf(child.getId())); Tree node = new Tree(); node.setId(String.valueOf(child.getId())); node.setPid(String.valueOf(child.getPid())); node.setText(child.getName()); node.setChildren(null); node.setState(count > 0 ? "closed" : "open"); //将儿子列表childrenList数据逐个存到树当中 result.add(node); } } return result; } catch (Exception e) { throw new BusinessException("获取图书类型数据出现错误!",e); } }

Dao层 :

代码如下:
getChildrenType(String pid) { //这个的pid就是当前展开节点的id,通过父节点的 id 来获得子节点 StringBuilder sqlstr = new StringBuilder(); if (StringUtils.isBlank(pid)) sqlstr.append("select * from booktype bt where bt.pid=0"); else sqlstr.append("select * from booktype bt where bt.pid=" + pid ); return this.search2(TBookType.class,sqlstr.toString()); }

代码如下:
sqlstr = new StringBuilder(); if (StringUtils.isBlank(pid)) sqlstr.append("select count(*) from booktype tb where tb.pid='0'"); else sqlstr.append("select count(*) from booktype tb where tb.pid='" + pid + "'"); return this.count(sqlstr.toString()); }

以上所述就是本文关于EasyUI实现异步树的全部代码了,希望对大家能有所帮助

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐