1
回答
beforeRename的处理问题
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

@zTree 你好,想跟你请教个问题:

做的异步加编辑的里面的beforeRename函数,如果是返回false的话,整个页面跟着就重载了,然后返回true的时候,当前节点跟着的三个按钮就一直显示不会根据是否hover来消失了,能帮忙看看吗?

详细代码:
var setting = {
async: {
enable: true,

autoParam: ["level", "id"],
type: 'get',
dataType: 'jsonp',
dataFilter: filter
},
view: {expandSpeed:"",
addHoverDom: addHoverDom,
removeHoverDom: removeHoverDom,
selectedMulti: false
},
edit: {
enable: true,
removeTitle: '删除',
renameTitle: '重命名'
},
data: {
simpleData: {
enable: true
}
},
callback: {
onAsyncSuccess: onAsyncSuccess,
beforeRemove: beforeRemove,
beforeRename: beforeRename
}
};
var maxLevel = 2;
function onAsyncSuccess(event, treeId, treeNode, msg) {

if (treeNode && treeNode.level >= maxLevel - 1) {
return;
}
var zTreeObj = $.fn.zTree.getZTreeObj("treeDemo");
var i, j, node;
var nodes = treeNode ? treeNode.children : zTreeObj.getNodes();
for (i = 0, j = nodes.length; i < j; i++) {
node = nodes[i];
if (node.isParent) {
zTreeObj.expandNode(node, true, false, false);
}
}
}
function onDblClick(event, treeId, treeNode) {
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
zTree.reAsyncChildNodes(treeNode, "refresh");
};

function filter(treeId, parentNode, childNodes) {

if (!childNodes) return null;
for (var i = 0, l = childNodes.length; i < l; i++) {

childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
}
return childNodes;
}
function beforeRemove(treeId, treeNode) {
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
zTree.selectNode(treeNode);
if (confirm("确认删除 节点 -- " + treeNode.name + " 吗?")) { 
$.ajax({

type: "get",
async: true,
dataType: "jsonp",
jsonp: 'callback',
data: {
level: treeNode.level,
id: treeNode.id
},
success: function (res) {

if (res.errNum == 0) {
alert('删除成功!'); 
return true;
} else {
alert('删除失败!');
return false;

}
}
});
} else {
return false;
}
}
function beforeRename(treeId, treeNode, newName) {
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
if (newName.length == 0) {
setTimeout(function () {
zTree.cancelEditName();
alert('节点名称不能为空.');

}, 0);
return false;
} else {
$.ajax({

type: "get",
async: true,
dataType: "jsonp",
jsonp: 'callback',
data: {
level: treeNode.level,
id: treeNode.id,
name: newName
},
success: function (res) {
if (res.errNum == 0) {
alert('修改成功!');
} else {
alert('修改失败!');
}
}
});
return true;
}

};

var newCount = 1;
function addHoverDom(treeId, treeNode) {
var sObj = $("#" + treeNode.tId + "_span");
if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
+ "' title='添加' onfocus='this.blur();'></span>";
if(treeNode.level < 5)
sObj.after(addStr);
var btn = $("#addBtn_"+treeNode.tId);
if (btn) btn.bind("click", function(){

if (confirm("确认为 " + treeNode.name + " 添加子节点吗?")) {
// zTree.addNodes(treeNode, { id: (100 + newCount), pId: treeNode.id, name: "new node" + (newCount++) });
var treeInfo = treeNode.id;
var add_level = treeNode.level + 1;
$.ajax({

type: "get",
async: false,
dataType: "jsonp",
jsonp: 'callback',
data: {
level: add_level,
id: treeInfo,
name: add_level + "-newnode"
},
success: function (res) {
if (res.errNum == 0) {
alert('添加成功!');
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
zTree.addNodes(treeNode, { id: res.NewID, pId: treeNode.id, name: add_level + "-newnode" });
} else {
alert('添加失败!'); 


}
});
}
return false;
});

};
function removeHoverDom(treeId, treeNode) {
$("#addBtn_"+treeNode.tId).unbind().remove();
};
$(document).ready(function () {
$.fn.zTree.init($("#treeDemo"), setting);
});

<无标签>
举报
xiaoixoaid
发帖于8个月前 1回/56阅
顶部