<SCRIPT type="text/javascript"> var setting = { check: { enable: true, chkStyle: "checkbox", chkboxType : { "Y" : "", "N" : "" } }, //获取json数据 async : { enable : true, url : "http://127.0.0.1:8080/contact/resource.do?method=getzTreeNodes", // Ajax 获取数据的 URL 地址 autoParam : [ "id", "name" ], //ajax提交的时候,传的是id值 otherParam: ["contactid",function(){ return window.opener.document.getElementById("contactid").value; }] }, data:{ // 必须使用data simpleData : { enable : true, idKey : "id", // id编号命名 pIdKey : "pId", // 父id编号命名 rootId : 0 } }, // 回调函数 callback : { onClick : function(event, treeId, treeNode, clickFlag) { if(true) { alert(" 节点id是:" + treeNode.id + ", 节点文本是:" + treeNode.name); } }, //捕获异步加载出现异常错误的事件回调函数 和 成功的回调函数 onAsyncSuccess : function(event, treeId, treeNode, msg){ // alert("调用成功!"); //var nodes=getCheckedNodes(true)); //alert(nodes); }, beforeClick: beforeClick, onCheck: onCheck } }; function beforeClick(treeId, treeNode) { var zTree = $.fn.zTree.getZTreeObj("treeDemo"); zTree.checkNode(treeNode, !treeNode.checked, null, true); return false; } var code; function showCode(str) { if (!code) code = $("#code"); code.empty(); code.append("<li>"+str+"</li>"); } $(document).ready(function(){ $.fn.zTree.init($("#treeDemo"), setting); //setCheck(); }); function onCheck(e,treeId,treeNode) { var zTree = $.fn.zTree.getZTreeObj("treeDemo"), nodes = zTree.getCheckedNodes(true), v = ""; var ids=""; for (var i=0, l=nodes.length; i<l; i++) { v += nodes[i].name + ","; ids+=nodes[i].id+","; } if (ids.length > 0 ) ids = ids.substring(0, ids.length-1); alert(ids); if (v.length > 0 ) v = v.substring(0, v.length-1); cityObjIds=window.opener.document.getElementById("cateSelIds").value=ids; cityObjName=window.opener.document.getElementById("cateSelName").value=v; } function getSelectedNodes() { var zTree = $.fn.zTree.getZTreeObj("treeDemo"), nodes = zTree.getCheckedNodes(true), v = ""; var ids=""; for (var i=0, l=nodes.length; i<l; i++) { v += nodes[i].name + ","; ids+=nodes[i].id+","; } if (ids.length > 0 ) ids = ids.substring(0, ids.length-1); alert(ids); if (v.length > 0 ) v = v.substring(0, v.length-1); //var cityObj = $("#citySel"); //var cityObjIds = $("#citySelIds"); //给父窗体updateContact.jsp中所属分类赋值 window.opener.document.getElementById("cateSelIds").value=ids; window.opener.document.getElementById("cateSelName").value=v; } function winClose() { window.close(); } lt;/SCRIPT> |