Home  >  Article  >  Web Front-end  >  EasyUI implements synchronization tree in jquery_jquery

EasyUI implements synchronization tree in jquery_jquery

WBOY
WBOYOriginal
2016-05-16 16:12:021069browse

In JS, just write the url address of the display tree as the address of the control.

control:

Copy code The code is as follows:

@RequestMapping(value = "/tree")
public void tree(HttpServletRequest request, HttpServletResponse response) throws IOException {
This.writeJson(response, bookService.getTree());
}

dao:

Copy code The code is as follows:

/**
* Get tree
​*/
@Override
public List getTree(){
try {
List trees = new ArrayList();
List 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;
}
}
/**
* Recursion
​*/
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 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);//Recursion
}
}
}
Return treenode;
} catch (Exception e) {
throw new BusinessException("Error getting data!", e);
}
}

The above is all the core code for implementing synchronization tree using EasyUI. I hope you will like it.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn