ztree的异步设置
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<link rel="stylesheet" href="libs/zTree_v3-master/css/zTreeStyle/zTreeStyle.css" type="text/css" />
<script type="text/javascript" src="libs/zTree_v3-master/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="libs/zTree_v3-master/js/jquery.ztree.core.js"></script>
<script>
var zNodes;
//setting异步加载的设置
var setting = {
treeId:"",
treeObj:null,
async: {
enable: true, //表示异步加载生效
contentType : "application/x-www-form-urlencoded",
dataFilter: null,
url: "ajax/Tree.ashx", // 异步加载时访问的页面
autoParam: ["id=tid"], // 异步加载时自动提交的父节点属性的参数
otherParam: ["action", 'AnsyDepartmentData'], //ajax请求时提交的参数
type: 'post',
dataType: 'json'
},
data: { //用pId来标识父子节点的关系
simpleData: {
enable: true
}
},
callback: { // 回调函数
onClick: zTreeOnClick, // 单击鼠标事件
}
};
//初始化加载节点
function Inint() {
$.ajax({
url: 'ajax/Tree.ashx',
type: 'post',
dataType: 'json',
async: false,
data: { 'action': 'AnsyDepartmentData' },
success: function (data) {
zNodes = data;
}
});
};
function zTreeOnClick(event, treeId, treeNode, clickFlag) {
var treeValue = treeNode.id + "," + treeNode.name;
//alert(treeNode.id + "," + treeNode.name);
};
//初始化绑定
$(document).ready(function () {
Inint();
$.fn.zTree.init( $("#treeDemo"), setting, zNodes);
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div class="content_wrap" >
<div class="zTreeDemoBackground right">
<ul id="treeDemo" class="ztree"></ul>
</div>
</div>
</form>
</body>
</html>