<!DOCTYPE html>
<HTML>
<HEAD>
<TITLE> ZTREE DEMO - Async</TITLE>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="css/demo.css" type="text/css">
<link rel="stylesheet" href="css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="js/jquery.ztree.excheck.js"></script>
<script type="text/javascript" src="js/jquery.ztree.exedit.js"></script>
</HEAD>
<BODY>
<ul id="treeDemo" class="ztree"></ul>
<table>
<tr>
<td class="title"><a href="javascript:void(0)">test1</a></td>
<td class="filePath">
n1/n1.n1/n1.n1.n1/n1.n1.n1.n3<br>
n3/n3.n2
</td>
</tr>
<tr>
<td class="title"><a href="javascript:void(0)">test2</a></td>
<td class="filePath">
n1/n1.n1/n1.n1.n1/n1.n1.n1.n4<br>
n3/n3.n3.n1/n3.n3.n1.n2
</td>
</tr>
</table>
<SCRIPT type="text/javascript">
<!--
var setting = {
check: {
enable: true
},
async: {
enable: true,
url:"demo/cn/asyncData/getNodes.php",
autoParam:["id", "name=n", "level=lv"],
otherParam:{"otherParam":"zTreeAsyncTest"},
dataFilter: filter
},
callback: {
onAsyncSuccess: onAsyncSuccess
}
};
var zTreeObj;
$(document).ready(function(){
zTreeObj = $.fn.zTree.init($("#treeDemo"), setting);
});
function filter(treeId, parentNode, childNodes) {
if (!childNodes)
return null;
childNodes.forEach(function(childNode){
// 计算路径
var path = '';
if(!parentNode){
path = childNode.name;
}else{
path = parentNode.filePath + '/' + childNode.name;
}
childNode.filePath = path;
// 判断是否已选中
var checked = false;
var halfCheck = false;
var chkDisabled = false;
$(".filePath").each(function(i, item){
var filePathArray = $(item).text().trim().split('
');
filePathArray.forEach(function(filePath){
filePath = filePath.trim();
if(filePath == childNode.filePath){// 全匹配(叶节点)
checked = true;
if(jQuery.inArray(filePath,filterFilePathArray) < 0){
chkDisabled = true;
}
}else if(filePath.indexOf(childNode.filePath) == 0){// 部分匹配(父节点)
checked = true;
// halfCheck = true;
}
});
});
childNode.checked = checked;
childNode.halfCheck = halfCheck;
childNode.chkDisabled = chkDisabled;
});
return childNodes;
}
function onAsyncSuccess(event, treeId, treeNode, msg) {
}
//-->
</SCRIPT>
<SCRIPT type="text/javascript">
<!--
var filterFilePathArray = [];
$(document).ready(function(){
$(".title a").click(function(){
filterFilePathArray = [];
var filePathArray = $(this).parents(".title").siblings(".filePath").text().trim().split('
');
filePathArray.forEach(function(filePath){
filePath = filePath.trim();
filterFilePathArray.push(filePath);
});
zTreeObj.destroy();
zTreeObj = $.fn.zTree.init($("#treeDemo"), setting);
});
});
//-->
</SCRIPT>
</BODY>
</HTML>