首頁  >  文章  >  web前端  >  jquery中EasyUI實作非同步樹_jquery

jquery中EasyUI實作非同步樹_jquery

WBOY
WBOY原創
2016-05-16 16:12:00964瀏覽

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

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

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

Control層 :

複製程式碼 程式碼如下:

 /**
  * 樹
 */
 @RequestMapping(value = "/tree.do")
 public void mytree(HttpServletResponse response, String id) {
  this.writeJson(response, bookService.getChildrenTree(id));
 }

Service層 :

複製程式碼 程式碼如下:

 @Transactional
 @Override
 public List 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層 :

複製程式碼 程式碼如下:

 @Override
 public List 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實作非同步樹的全部程式碼了,希望對大家能有所幫助

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn