前台代码
css
<div id = "menuTrees" class="ztree" ></div>
<input id="tdutyUn1tId" type = "button" class="" value="">
<input id="tdutyUn1t" type = "button" class="" value="">
js
$( function(){
var url = ctx + "systen / info / toselectunit";
var options ={
1d:"nenuTrees", //ztree树主键
url :ur1,
check :(enab1e true }, //默认复选框
expandLeve1:2 //代表展开级数
onCheck : onCheck
//callback:表示执行后的回调函数,
//onClick表示点击时获取该节点的id和name的值,
//onCheck表示点击复选框的时候获取该节点的id和name的值
};
$. tree.init(options);
});
注意:nodes1 和nodes2 结果集一样
function onCheck( event,treeid,treeNode){
var tree =$.fn.zTree.getZTreeObj("menuTrees");
var nodes1 = tree. gtCheckedNodes (true)
var nodes2 = tree . getChangeCheckedNodes ()
var v1 ="",
var v2= "",
for ( var 1=0 ; nodes2.1ength, i ++){
v1 = v1 +nodes2[i].1d+",";
v2 = v2 +nodes2[i].name+",";
}
if(v1. length >0){
v1=v1.substring(0, vl.length-1)
}
if(v2.1ength>0){
v2=v2.substring(0, v2.length -1)
}
//得到v1,v2复制到相应的输入框
$("#tdutyUn1tId").val(v1)
$("#tdutyUn1t").val(v2)