jquery中EasyUI实现同步树
更新时间:2015年03月01日 11:45:28 投稿:hebedich
本文主要是给大家分享了一则使用EasyUI实现同步树的代码,主要是使用递归实现,非常实用的方法,推荐给小伙伴们。
在JS中,将显示树的url地址写成control的地址即可.
control:
复制代码 代码如下:
@RequestMapping(value = "/tree")
public void tree(HttpServletRequest request, HttpServletResponse response) throws IOException {
this.writeJson(response, bookService.getTree());
}
dao:
复制代码 代码如下:
/**
* 获取树
*/
@Override
public List<Tree> getTree(){
try {
List<Tree> trees = new ArrayList<Tree>();
List<TBookType> root = this.search(0);
if(root != null && root.size() > 0){
for(TBookType tb : root){
Tree rootnode = this.getNode(tb);
rootnode.setState("open");
trees.add(rootnode);
}
}
return trees;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 递归
*/
private Tree getNode(TBookType node){
if(node == null){
return null;
}
try {
Tree treenode = new Tree();
treenode.setId(String.valueOf(node.getId()));
treenode.setText(node.getName());
treenode.setPid(String.valueOf(node.getPid()));
List<TBookType> children = this.search(node.getId());
if(children != null && children.size() > 0){
treenode.setState("closed");
for(TBookType child : children){
Tree childnode = this.getNode(child);
if(childnode != null){
treenode.getChildren().add(childnode);//递归
}
}
}
return treenode;
} catch (Exception e) {
throw new BusinessException("获取数据出错!", e);
}
}
以上就是使用EasyUI实现同步树的全部核心代码了,希望大家能够喜欢。
相关文章
jquery validate.js表单验证入门实例(附源码)
这篇文章主要介绍了jquery validate.js表单验证入门实例,为大家提供了jquery validate.js表单验证的源码,特别适合初学者学习validate.js表单验证,感兴趣的小伙伴们可以参考一下2015-11-11
JQuery FlexiGrid的asp.net完美解决方案 dotNetFlexGrid-.Net原生的异步表格控件
dotNetFlexGrid是一款dotNet原生的异步表格控件,他的前身是Jquery FlexiGrid插件,我们重构了FlexiGrid的大部分Javascript代码,使其工作的更有效率,BUG更少;同时将其封装为dotNet控件,提供了简单易用的使用方式。2010-09-09


最新评论