In JS, just write the url address of the display tree as the address of the control.
control:
@RequestMapping(value = "/tree")
public void tree(HttpServletRequest request, HttpServletResponse response) throws IOException {
This.writeJson(response, bookService.getTree());
}
dao:
/**
* 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.