首先要配置右侧按钮不可用,然后利用onNodeCreated方法编辑右侧的按钮
edit: {
enable: false,
showRenameBtn:false,
},
callback: {
onNodeCreated: orgzTreeOnNodeCreated
}
function orgzTreeOnNodeCreated(event, treeId, treeNode) {
console.log(treeId, treeNode);
var aObj = $("#" + treeNode.tId + "_a");
if ($("#diyBtn_"+treeNode.id).length>0) return;
var editStr = "<span id='diyBtn_space_" +treeNode.id+ "' ><i class='del-icon del-icon-"+ treeNode.id +" layui-icon layui-icon-close-fill '></i></span>"
+ "<button type='button' class='diyBtn1' id='diyBtn_" + treeNode.id
+ "' title='"+treeNode.name+"' onfocus='this.blur();'></button>";
aObj.append(editStr);
var btn = $(".del-icon-"+treeNode.id);
if (btn) btn.bind("click", function(){
var treeObj = ztreeS.fn.zTree.getZTreeObj("treeDemo");
treeObj.checkNode(treeObj.getNodesByParam("id", treeNode.id)[0], false, true);
var orgTreeObj = ztreeS.fn.zTree.getZTreeObj("orgTreeDemo");
orgTreeObj.removeNode(treeNode);
});
};