ztree check

时间:2021-10-21 02:13:09

<link rel="stylesheet" href="${contextPath}/resources/ztree/css/demo.css" type="text/css">
<link rel="stylesheet" href="${contextPath}/resources/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="${contextPath}/resources/ztree/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="${contextPath}/resources/ztree/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="${contextPath}/resources/ztree/js/jquery.ztree.excheck-3.5.js"></script>

<SCRIPT type="text/javascript">
var setting = {
view : {
selectedMulti : false
},
check : {
enable : true
},
data : {
simpleData : {
enable : true
}
},
callback : {
beforeCheck : beforeCheck,
onCheck : onCheck
}
};

var zNodes = [];

var code, log, className = "dark";
function beforeCheck(treeId, treeNode) {
className = (className === "dark" ? "" : "dark");

return (treeNode.doCheck !== false);
}
function onCheck() {
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
var nodes = zTree.getCheckedNodes();
var nodesid = '';
for (var i = 0; i < nodes.length; i++) {
nodesid += nodes[i].id + ',';
}

$('#chknodes').val(nodesid);
}
function showLog(str) {
if (!log)
log = $("#log");
log.append("<li class='"+className+"'>" + str + "</li>");
if (log.children("li").length > 6) {
log.get(0).removeChild(log.children("li")[0]);
}
}

$(document).ready(function() {

var s = $('#hinitnodes').val();
if (s != "") {
s = s.replace(/\'/g, "\"");
zNodes = JSON.parse(s);
}

$.fn.zTree.init($("#treeDemo"), setting, zNodes);
onCheck();
//$("#selectAll").bind("click", selectAll);
});
</SCRIPT>