您的位置:首页 > 产品设计 > UI/UE

easyUI tree点击文字展开节点

2014-11-03 17:48 204 查看
easyUI默认展开树的时候,点击节点前边的黑色小三角 ,这样操作存在不人性化的地方,在实际使用中由于老旧电脑的存在和大龄使用者的眼花经常点不准;因此要实现点击节点名称展开的方式,其实就是在展开事件上加一个展开该节点的方法。

在onSelect事件中添加

$(this).tree('expand',node.target);

当选中该节点的时候,展开该节点下的节点,该方法只会展开下一级节点,并不会展开子节点下的节点。

如果要展开所有节点:

$(this).tree('expandAll',node.target);
$(document).ready(function(){
$('#dept').layout();
$('#deptTree').tree({
checkbox:false,
url:'loadDeptJson.action?node=-1',
onBeforeExpand:function(node,param){
$('#deptTree').tree('options').url="loadDeptJson.action?node="+node.id;
},
onSelect:function(node){
$('#deptContent').load("viewDepartment.action?department.id="+node.id);
$(this).tree('expand',node.target);
},
});
});


给onclick绑定多个事件,如果部门有人,则在grid中显示人员,如果有子部门则展示下级部门
解决方案:
$("#dept_tree").tree({
url:"servlet/SearchServlet?dispatch=2&unit_id=" + unit_id+"&id=0",  //此处的url是加载树
onBeforeExpand:function(node,param){
$("#dept_tree").tree("options").url="servlet/SearchServlet?dispatch=2&unit_id=" + unit_id+"&id="+node.id;
},
onSelect:function(node){
$(this).tree("expand",node.target);  //展开点击的文本的子节点
},
});
onClick:function(node){
//alert("id"+node.id+"部门id是:" + node.attributes.department_id+"--单位--"+node.attributes.unit_id);
var url22 = "servlet/SearchServlet?dispatch=22&unit_id=" + node.attributes.unit_id;
$.getJSON(url22,{department_id:node.attributes.department_id},function(data){
if(data.length == 0){
var url = "servlet/SearchServlet?dispatch=3&department_id="+node.attributes.department_id;
$("#person_grid").datagrid({url:url,toolbar:results_grid_default_toolbar,columns:results_grid_default_columns})
}
});
},
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: