zTree v3.5.18 API 文档:
jquery-zTree引入的工具包:
引入js:
<link rel="stylesheet" href="<%=path%>/jquery-zTree/css/demo.css" type="text/css">
<link rel="stylesheet" href="<%=path%>/jquery-zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="<%=path%>/jquery-zTree/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="<%=path%>/jquery-zTree/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="<%=path%>/jquery-zTree/js/jquery.ztree.excheck-3.5.js"></script>
<script type="text/javascript" src="<%=path%>/jquery-zTree/js/jquery.ztree.exedit-3.5.js"></script>
js代码:
var setting = {
data: {
simpleData: {
enable: true
}
}
,async: {
enable: true,
url:"<%=path %>/包/类!方法.action",
autoParam:["id", "name", "level"], //传参
otherParam:{"otherParam":"zTreeAsyncTest"},
dataFilter: filter //获取数据执行
},callback:{
onCheck: zTreeOnCheck,
onAsyncError: zTreeOnAsyncError //加载错误的fun
}
};
//数据过滤
function filter(treeId, parentNode, childNodes) {
if (!childNodes) return null;
var child=eval('('+childNodes.returnArray+')');//将数据转换成数组对象
for (var i=0, l=child.length; i<l; i++) {
child[i].name = child[i].name.replace('','');
}
return child;
}
//异步加载错误提示
function zTreeOnAsyncError(){
alert("加载子菜单错误,请联系管理员处理");
}
//鼠标点击事件
function zTreeOnCheck(event, treeId, treeNode) {
//alert(treeNode.tId + ", " + treeNode.name + "," + treeNode.checked);
};
//根节点数据
var rootNodes=[{id:'0',pId:'',name:"第一节点",level:"0",nodeType:'root',isParent:true,iconSkin:"rootIcon"},
{id:'1',pId:'',name:"第二节点",level:"0",nodeType:'root',isParent:true,iconSkin:"rootIcon"},
{id:'2',pId:'',name:"第三节点",level:"0",nodeType:'root',isParent:true,iconSkin:"rootIcon"}];
$(document).ready(function(){
$.fn.zTree.init($("#tree"), setting, rootNodes);
});
Html代码:
<div class="content_wrap" style="float: left;">
<div class="zTreeDemoBackground left">
<ul id="tree" class="ztree"></ul>
</div>
</div>
注:zTree参数为数组,传值严格按照rootNodes。详细参照zTree API文档。
此为本人第一次用zTree插件的一些总结,如有问题,烦请大神门指出。