jquery中EasyUI實現(xiàn)異步樹
更新時間:2015年03月01日 11:52:37 投稿:hebedich
前面我們分享了使用jquery中EasyUI實現(xiàn)同步樹的代碼,本文我們就來看下使用EasyUI實現(xiàn)異步樹的方法和示例,希望小伙伴們能夠喜歡。
前臺使用EasyUI實現(xiàn) . EasyUI向后臺傳遞一個id參數(shù) .
第一次加載 , 向后臺傳遞的id為null .
之后每次將樹節(jié)點展開 , 會向后臺傳遞一個當前節(jié)點的 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é)點的列表
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ù)逐個存到樹當中
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就是當前展開節(jié)點的id , 通過父節(jié)點的 id 來獲得子節(jié)點
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就是當前展開節(jié)點的id , 通過父節(jié)點的 id 來獲得子節(jié)點的個數(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實現(xiàn)異步樹的全部代碼了,希望對大家能有所幫助
您可能感興趣的文章:
相關(guān)文章
jQuery Validation PlugIn的使用方法詳解
這篇文章主要介紹了jQuery Validation PlugIn的使用方法,需要的朋友可以參考下2015-12-12
CSS3 media queries結(jié)合jQuery實現(xiàn)響應(yīng)式導(dǎo)航
這篇文章主要為大家詳細介紹了CSS3 media queries結(jié)合jQuery實現(xiàn)響應(yīng)式導(dǎo)航,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-09-09
jquery結(jié)合css實現(xiàn)返回頂部功能
在本篇文章里小編給大家整理了一篇關(guān)于jquery結(jié)合css實現(xiàn)返回頂部功能的相關(guān)文章,有興趣的朋友們可以實例測試下。2021-08-08
基于jquery創(chuàng)建的一個圖片、視頻緩沖的效果樣式插件
利用css和jquery創(chuàng)建一個動畫效果的緩沖樣式插件,插件可以開始、暫停、結(jié)束2012-08-08

