代碼如下
//第一個樹
if(<%=value1%>!="1"){
var setting1 = {
check: {
enable: true,
chkStyle: "<%=chose1%>",
<%=type1%>Type: <%=typeValue1%>
},
view: {
dblClickExpand: false
},
data: {
simpleData: {
enable: true
}
},
callback: {
beforeClick: beforeClick,
onCheck: onCheck,
}
};
var zNodes1 =<%=value1%>;
function beforeClick(treeId, treeNode) {
var zTree = $.fn.zTree.getZTreeObj("treeDemo1");
if(treeNode.id.indexOf(".")==-1){
zTree.expandNode(treeNode);
}else if(treeNode.id.indexOf(".")!=-1 &&treeNode.id.length == 3 ){
zTree.expandNode(treeNode);
}else{
zTree.checkNode(treeNode, !treeNode.checked, null, true);
}
return false;
}
function onCheck(e,treeId,treeNode){
var checkPerson1= document.getElementById("checkPerson1");
var treeObj=$.fn.zTree.getZTreeObj("treeDemo1");
nodes=treeObj.getCheckedNodes(true);
var id1="";
for(var i=0;i<nodes.length;i++){
if(nodes[i].id!=""){
id1+="{'userId':'"+nodes[i].id+"','userName':'"+nodes[i].name+"','deptId':'"+nodes[i].deptId+"','userRole':'"+nodes[i].userRole+"','nextNodeType':'"+nodes[i].nextNodeType+"'};";
//alert("pppppp"+id1);
}
}
checkPerson1.value=id1;
}
$(document).ready(function(){
$.fn.zTree.init($("#treeDemo1"), setting1, zNodes1);
});
}
function showMenu() {
var cityObj = $("#citySel");
var cityOffset = $("#citySel").offset();
$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
// $("body").bind("mousedown", onBodyDown);
}
ztree前面是模擬的,不是checkbox,radio對象,需要自己添加onClick事件,然後調用checkNode方法進行操作
ztree點擊文字勾選checkbox,radio實現方法