jquery中EasyUI實現非同步樹,jqueryeasyui

來源:互聯網
上載者:User

jquery中EasyUI實現非同步樹,jqueryeasyui

前台使用EasyUI實現 . EasyUI向後台傳遞一個id參數 .

第一次載入 , 向後台傳遞的id為null .

之後每次將樹節點展開 , 會向後台傳遞一個當前節點的 id .

Control層 :

複製代碼 代碼如下:
 /**
  * tree
  */
 @RequestMapping(value = "/tree.do")
 public void mytree(HttpServletResponse response, String id) {
  this.writeJson(response, bookService.getChildrenTree(id));
 }

Service層 :

複製代碼 代碼如下:
 @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);
  }
 }

Dao層 :

複製代碼 代碼如下:
 @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());
 }

複製代碼 代碼如下:
 @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實現非同步樹的全部代碼了,希望對大家能有所協助

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.