ztree怎么获取节点选中变化的节点
发布网友
发布时间:2022-04-07 19:22
我来回答
共1个回答
热心网友
时间:2022-04-07 20:51
<script>
function filter(node) { //过滤器直选中2级节点累加
return (node.level == 2 && node.checked == true);
}
var setting = { //设置
check: {
enable: true
},
callback: {
onCheck: onCheck
}};
function onCheck(e, treeId, treeNode){ //这是将所有选中节点的名字 用,分割做拼接 用于持久化到数据库
var zTree = $.fn.zTree.getZTreeObj("tree").getNodesByFilter(filter);
var choose = "";
for (var i=0;i<zTree.length;i++) {
if(zTree[i].name !=null)
choose +=(i == (zTree.length-1))?zTree[i].name:zTree[i].name+",";
}
$("#ztreesnames").val(choose);
treeIds();
}
function treeIds(){ //这是将选中的节点的id用;分割拼接起来,用于持久化到数据库
var zTreeO = $.fn.zTree.getZTreeObj("tree").getNodesByFilter(filter);
var idListStr = "";
for (var i = 0; i < zTreeO.length; i++) {
if (zTreeO[i].id != null) {
idListStr+= (i == (zTreeO.length-1))?zTreeO[i].id:zTreeO[i].id+";";
}
};
$("#ztreeids").val(idListStr);