ztree复选框

<script type="text/javascript">
var setting = {
check: {
enable: true,
chkboxType : { "Y" : "", "N" : "" }
},
data: { 
           simpleData: { 
               enable: true,//如果设置为 true,请务必设置 setting.data.simpleData 内的其他参数: idKey / pIdKey / rootPId,并且让数据满足父子关系。 
           } 
       },
async: {
enable: true,
type: "post",
contentType: "application/json",
url:getAsyncUrl,
dataType:"json"
},
    callback: {
   onClick: zTreeOnClick
   }
};


function getAsyncUrl(treeId, treeNode) {
var nodeid=encodeURIComponent(treeNode.id);
var siteid=treeNode.siteid;
var url='<%=path%>/datacheck/asset/getTreeNodes?siteid='+siteid+'&nodeid='+nodeid;
    return url;
};

function zTreeOnClick(event, treeId, treeNode) {
    var url='<%=path%>/datacheck/asset/getChildAssetList?pId='+treeNode.id+'&siteid='+treeNode.siteid;
$("#childnodes").load(url);
};    
$(document).ready(function(){
$.ajax({
  type: 'POST',
  url: "<%=path%>/datacheck/asset/getTreeNodes",
  dataType: "json",//返回json格式的数据
  success: function(zNodes){
  $.fn.zTree.init($("#changeleveltree"), setting,zNodes);
  }
});

var url='<%=path%>/datacheck/asset/getChildAssetList?pId='+$("#parent").val()+'&siteid='+$("#siteid").val();
$("#childnodes").load(url);
});

//获取选中的树节点
function getCheckNodes(){
var treeObj = $.fn.zTree.getZTreeObj("changeleveltree");
var nodes = treeObj.getCheckedNodes(true);
if(nodes.length==0){
alert('没有选中任何节点');
return false;
}else if(nodes.length>1){
alert('只能选择一个节点作为上级节点');
return false;
}
var url = '<%=path%>/datacheck/asset/changeParentNode';
$.ajax({
   type: "POST",
   url: url,
   data: {'siteid': $("#siteid").val(), 'assetNum': $("#assetNum").val(), 'parent':nodes[0].id},
   success: function(msg){
   $(window.parent.document).contents().find("#assetTreeFrame")[0].contentWindow.rereshNode(nodes[0].id);
   $(window.parent.document).contents().find("#assetTreeFrame")[0].contentWindow.rereshParentNode($("#assetNum").val());
   },
   error: function(msg){
      alert("修改失败,请联系管理员");
   },
   dataType: 'text'
});
$(".close").click();
}
</SCRIPT>

你可能感兴趣的:(ztree)