jquery中EasyUI实现同步树
在JS中,将显示树的url地址写成control的地址即可.
control:
@RequestMapping(value="/tree")
publicvoidtree(HttpServletRequestrequest,HttpServletResponseresponse)throwsIOException{
this.writeJson(response,bookService.getTree());
}
dao:
/**
*获取树
*/
@Override
publicList<Tree>getTree(){
try{
List<Tree>trees=newArrayList<Tree>();
List<TBookType>root=this.search(0);
if(root!=null&&root.size()>0){
for(TBookTypetb:root){
Treerootnode=this.getNode(tb);
rootnode.setState("open");
trees.add(rootnode);
}
}
returntrees;
}catch(Exceptione){
e.printStackTrace();
returnnull;
}
}
/**
*递归
*/
privateTreegetNode(TBookTypenode){
if(node==null){
returnnull;
}
try{
Treetreenode=newTree();
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(TBookTypechild:children){
Treechildnode=this.getNode(child);
if(childnode!=null){
treenode.getChildren().add(childnode);//递归
}
}
}
returntreenode;
}catch(Exceptione){
thrownewBusinessException("获取数据出错!",e);
}
}
以上就是使用EasyUI实现同步树的全部核心代码了,希望大家能够喜欢。