配置信息如下:
var UsersTreeSetting = {
check : {
enable : true,
chkboxType : {
"Y" : "ps",
"N" : "ps"
}
},
view : {
dblClickExpand : false,
selectedMulti: false
},
data : {
simpleData : {
enable : true
}
},
callback : {
beforeClick : function(treeId, treeNode) {
var zTree = $.fn.zTree.getZTreeObj("add-user-modal-users-tree");
zTree.checkNode(treeNode, !treeNode.checked, true, true);
return true;
},
onCheck : function(e, treeId, treeNode) {
var zTree = $.fn.zTree.getZTreeObj("add-user-modal-users-tree"),
nodes = zTree.getCheckedNodes(true),
v = "";
chosenUsersIds = [];
for (var i = 0, l = nodes.length; i < l; i++) {
if (nodes[i].isParent) { } else {
//v += nodes[i].name + ",";//只获取最末端节点的值
chosenUsersIds.push(nodes[i].id);
}
}
if(chosenUsersIds.length == 0){
toastr.info("当前选择的用户数为0哦!", "信息提示");
}
// if (v.length >= 0){
// v = v.substring(0, v.length - 1);
// $("#add-user-modal-users").val(v).change();
// console.log(v);
// }
}
}
};
其中的chkboxType配置和beforeClick事件后的函数是关键。