源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

jquery中EasyUI实现异步树

  • 时间:2021-06-19 00:58 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:jquery中EasyUI实现异步树
前台使用EasyUI实现 . EasyUI向后台传递一个id参数 . 第一次加载 , 向后台传递的id为null . 之后每次将树节点展开 , 会向后台传递一个当前节点的 id . [b]Control层 :[/b]
[u]复制代码[/u] 代码如下:
 /**   * tree   */  @RequestMapping(value = "/tree.do")  public void mytree(HttpServletResponse response, String id) {   this.writeJson(response, bookService.getChildrenTree(id));  }
[b]Service层 :[/b]
[u]复制代码[/u] 代码如下:
 @Transactional  @Override  public List<Tree> getChildrenTree(String pid) {   try {    List<Tree> result = new ArrayList<Tree>();    //获得儿子节点的列表    List<TBookType> 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);   }  }
[b]Dao层 :[/b]
[u]复制代码[/u] 代码如下:
 @Override  public List<TBookType> 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());  }
[u]复制代码[/u] 代码如下:
 @Override  public long getChildrenCount(String pid) {  //这个的pid就是当前展开节点的id , 通过父节点的 id 来获得子节点的个数   StringBuilder 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实现异步树的全部代码了,希望对大家能有所帮助
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部