<ul id="tt"></ul>
$('#tt').tree({
url:'/demo2/node/getNodes' // The url will be mapped to NodeController class and getNodes method
});
@Table(name="nodes")
public class Node extends ActiveRecordBase{
@Id public Integer id;
@Column public Integer parentId;
@Column public String name;
public boolean hasChildren() throws Exception{
long count = count(Node.class, "parentId=?", new Object[]{id});
return count > 0;
}
}
public class NodeController extends ApplicationController{
/**
* get nodes, if the 'id' parameter equals 0 then load the first level nodes,
* otherwise load the children nodes
* @param id the parent node id value
* @return the tree required node json format
* @throws Exception
*/
public View getNodes(int id) throws Exception{
List<Node> nodes = null;
if (id == 0){ // return the first level nodes
nodes = Node.findAll(Node.class, "parentId=0 or parentId is null", null);
} else { // return the children nodes
nodes = Node.findAll(Node.class, "parentId=?", new Object[]{id});
}
List<Map<String,Object>> items = new ArrayList<Map<String,Object>>();
for(Node node: nodes){
Map<String,Object> item = new HashMap<String,Object>();
item.put("id", node.id);
item.put("text", node.name);
// the node has children,
// set the state to 'closed' so the node can asynchronous load children nodes
if (node.hasChildren()){
item.put("state", "closed");
}
items.add(item);
}
return new JsonView(items);
}
}
$('#tt').tree({
method:"POST",
url:'/demo2/node/getNodes' // The url will be mapped to NodeController class and getNodes method
});
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有