1:前台easyUI tree DOM元素定义:
<ul id="virtual_host_tree_Screen" animate="true" dnd="false">
</ul>
2:JS控制层初始化TREE
$('#virtual_host_tree_Screen').tree({
url : 'host/virtual/',
method : 'GET',
animate : true,
onClick : function(node) {
if (node.attributes == 0) {
$('#virtual_host_tree_Screen').tree('expand', node.target);
} else {
_this.selVm_Screen(node.id);
}
}
});
3:后台Control层写法:
List<Map<String, Object>> list = new ArrayList<Map<String,Object>>(hosts.size());
Map<String, Object> hostJson = null;
for(THost host : hosts){
hostJson = new HashMap<String, Object>(2);
hostJson.put("id", host.getId());
hostJson.put("text", host.getHostname());
hostJson.put("state", state);
hostJson.put("attributes", host.getVirtual());
list.add(hostJson);
}
return list;
4 后台JSON数据返回前台格式:
第一次加载 id = 0,即:http://192.168.0.248:8080/vCat/host/virtual/
第二层展开异步加载,根据点击树节点的ID进行自动查询:
http://192.168.0.248:8080/vCat/host/virtual/?id=101