欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery中EasyUI實(shí)現(xiàn)異步樹

 更新時間:2015年03月01日 11:52:37   投稿:hebedich  
前面我們分享了使用jquery中EasyUI實(shí)現(xiàn)同步樹的代碼,本文我們就來看下使用EasyUI實(shí)現(xiàn)異步樹的方法和示例,希望小伙伴們能夠喜歡。

前臺使用EasyUI實(shí)現(xiàn) . EasyUI向后臺傳遞一個id參數(shù) .

第一次加載 , 向后臺傳遞的id為null .

之后每次將樹節(jié)點(diǎn)展開 , 會向后臺傳遞一個當(dāng)前節(jié)點(diǎn)的 id .

Control層 :

復(fù)制代碼 代碼如下:

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

Service層 :

復(fù)制代碼 代碼如下:

 @Transactional
 @Override
 public List<Tree> getChildrenTree(String pid) {
  try {
   List<Tree> result = new ArrayList<Tree>();
   //獲得兒子節(jié)點(diǎn)的列表
   List<TBookType> childrenList = this.getChildrenType(pid);
   if (childrenList != null && childrenList.size() > 0) {
    for (TBookType child : childrenList) {
     // 獲取孫子的個數(shù)
     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數(shù)據(jù)逐個存到樹當(dāng)中
     result.add(node);
    }
   }
    return result;
  } catch (Exception e) {
   throw new BusinessException("獲取圖書類型數(shù)據(jù)出現(xiàn)錯誤!", e);
  }
 }

Dao層 :

復(fù)制代碼 代碼如下:

 @Override
 public List<TBookType> getChildrenType(String pid) {
 //這個的pid就是當(dāng)前展開節(jié)點(diǎn)的id , 通過父節(jié)點(diǎn)的 id 來獲得子節(jié)點(diǎn)
 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());
 }

復(fù)制代碼 代碼如下:

 @Override
 public long getChildrenCount(String pid) {
 //這個的pid就是當(dāng)前展開節(jié)點(diǎn)的id , 通過父節(jié)點(diǎn)的 id 來獲得子節(jié)點(diǎn)的個數(shù)
  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());
 }
 

以上所述就是本文關(guān)于EasyUI實(shí)現(xiàn)異步樹的全部代碼了,希望對大家能有所幫助

相關(guān)文章

最新評論