jQuery EasyUI API 中文文档 - Tree树使用示例
//加载部门树
$(function() {
$('#deptTree').tree({
// animate: true,
//cascadeCheck : false,
url : 'departOrPerson.action?type=dept',
Style : function(index, row) {
return 'background-color:pink;color:blue;font-weight:bold;';
},
onClick : function(node) {
$("#deptname").val("");
loadifrDept(node.id);
},
onContextMenu:function(e,node){
if (node.attributes.parentid != "0") {//集团根目录的parentid为0,集团名称不能在此修改,不能删除
rightmenu(
'myMenu' + node.id + '',
{menuList : [{
menuName : "修改",
clickEvent : "alterDept('" + node.id + "')"
},{
menuName : "删除",
clickEvent : "deleteDept('" + node.id + "','" + node.text + "')"
}]
});
} else {
rightmenu(
'myMenu' + node.id + '',
{menuList : [{
menuName : "修改",
clickEvent : "altermessage()"
},{
menuName : "删除",
clickEvent : "altermessageDel()"
}]
});
}
stopDefault(e);
},
onBeforeExpand:function(node,param){
// $(this).tree('options').url = 'departOrPerson.action?Id=dept';
var children = $('#deptTree').tree('getChildren', node.target);
if(children.length<=1){
$.ajax( {
type : 'POST',
dataType : "json",
url : 'departOrPerson.action',
data:"type=dept&Id="+node.id,
success : function(data) {
// var json = eval(arguments[2].responseText);
for(var i=0; i<children.length; i++){
$('#deptTree').tree('remove', children[i].target);
}
$('#deptTree').tree('append', {
parent: node.target,
data: data
});
$('#deptTree').tree('expand',node.target);
}
});
} //end of if
}
});
});
function altermessage() {
$.messager.alert("操作提示","不能修改集团名称!","warning");
}
function altermessageDel() {
$.messager.alert("操作提示","不能删除集团名称!","warning");
}
function alterDept(deptid) {
var formalterDeptObj = document.form1;
formalterDeptObj.action = "deptManage_edit.action?deptid=" + deptid;
formalterDeptObj.submit();
}
function deleteDept(deptid, deptname) {
var sid = deptid;
$.messager.confirm('确认', '确认要删除部门"' + deptname + '"吗?', function(r) {
if (r) {
$.ajax( {
type : 'POST',
url : 'deptManage_delete.action?type=deleteCheck&deptid=' + sid,
success : function(data) {
var json = eval(arguments[2].responseText);
if (json[0].result == "ok") {
$("#deptTree").tree("reload");
} else {
//$.messager.alert("操作提示","请先解除部门\"" + deptname + "\"的下级部门以及员工!","warning");
$.messager.confirm('警告', '此操作将删除部门"' + deptname + '"的下级所有部门以及下级员工,确认执行吗?', function(s) {
if (s) {
$.ajax( {
type : 'POST',
url : 'deptManage_delete.action?type=delete&deptid=' + sid,
success : function(data) {
var json = eval(arguments[2].responseText);
if (json[0].result == "ok") {
$("#deptTree").tree("reload");
} else {
$.messager.alert("操作提示","删除失败!","warning");
}
}
});
}
});
}
}
}