树形结构中checkbox="true"表示树节点是可以选择。
<div id="left">
<ul id="tt" class="easyui-tree" checkbox="true"></ul>
</div>
/**
*
*@User :Test
*@date :2014-6-18 下午03:19:28
*@return :Object
*@userFor : 生成树型数据
*/
public List<Map<String, Object>> queryMenusList(String parentId)
{
List<Map<String, Object>> result = new ArrayList<Map<String,Object>>();
// 找到下层子节点
List<xx> allItem = this.menuDao.queryMenusList(parentId);
for(xx v:allItem)
{
Map<String, Object> item = new HashMap<String, Object>();
item.put("id", v.getUrl());
item.put("text", v.getName());
//判断是否加载时选中值
item.put("checked", "true");
List<xx> childItem = this.menuDao.queryMenusList(v.getEventid()) ;
if(childItem.size()>0)
{
item.put("state", "closed");
item.put("children", toJsons(childItem));
}
result.add(item);
}
return result ;
}
public List<Map<String, Object>> toJsons(List<xx> list)
{
List<Map<String, Object>> items = new ArrayList<Map<String, Object>>();
for (int i = 0; i < list.size(); i++)
{
xx bo = (xx) list.get(i);
Map<String, Object> item = new HashMap<String, Object>();
item.put("id", bo.getUrl());
item.put("text",bo.getName() );
List<xx> temps = this.menuDao.queryMenusList(bo.getEventid());
if (temps.size() > 0)
{
item.put("state", "closed");
item.put("children", toJsons(temps));
}
items.add(item);
}
return items;
}
得到选中的值方法
var node = $('#tt').tree('getChecked');
//得到id值返回后台处理
for(var i=0;i<node.length;i++){
ids+=node[i].id+",";
}
Js加载后台
$('#tt').tree({
url:'./getLeftTree.do?treeHasClient=yes',
onCheck:function(node){
},
//右键生成菜单 e.pageX自动生成
onContextMenu:function(e,node){
$('#mm').menu('show', {
left: e.pageX,
top: e.pageY
});
},
//双击事件
onDblClick:function(node){
}
})
//右键后的菜单
<div id="mm" class="easyui-menu" style="width:100px;">
<div herf="#" onclick="xx()">Test1</div>
<div herf="#" onclick="xx()">Test2</div>
<div herf="#" onclick="xx()">Test3</div>
<div herf="#" onclick="xx()">Test4</div>
</div>