004068fb966613b854a04804fdd88be3335e3a02.svn-base
5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!DOCTYPE html>
<HTML>
<HEAD>
<TITLE> ZTREE DEMO - reAsyncChildNodes</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-3.5.js"></script>
<!-- <script type="text/javascript" src="../../../js/jquery.ztree.excheck-3.5.js"></script>
<script type="text/javascript" src="../../../js/jquery.ztree.exedit-3.5.js"></script>-->
<SCRIPT type="text/javascript">
<!--
var setting = {
view: {
selectedMulti: false
},
async: {
enable: true,
url:"../asyncData/getNodes.php",
autoParam:["id", "name=n", "level=lv"],
otherParam:{"otherParam":"zTreeAsyncTest"},
dataFilter: filter
},
callback: {
beforeClick: beforeClick,
beforeAsync: beforeAsync,
onAsyncError: onAsyncError,
onAsyncSuccess: onAsyncSuccess
}
};
function filter(treeId, parentNode, childNodes) {
if (!childNodes) return null;
for (var i=0, l=childNodes.length; i<l; i++) {
childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
}
return childNodes;
}
function beforeClick(treeId, treeNode) {
if (!treeNode.isParent) {
alert("请选择父节点");
return false;
} else {
return true;
}
}
var log, className = "dark";
function beforeAsync(treeId, treeNode) {
className = (className === "dark" ? "":"dark");
showLog("[ "+getTime()+" beforeAsync ] " + ((!!treeNode && !!treeNode.name) ? treeNode.name : "root") );
return true;
}
function onAsyncError(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {
showLog("[ "+getTime()+" onAsyncError ] " + ((!!treeNode && !!treeNode.name) ? treeNode.name : "root") );
}
function onAsyncSuccess(event, treeId, treeNode, msg) {
showLog("[ "+getTime()+" onAsyncSuccess ] " + ((!!treeNode && !!treeNode.name) ? treeNode.name : "root") );
}
function showLog(str) {
if (!log) log = $("#log");
log.append("<li class='"+className+"'>"+str+"</li>");
if(log.children("li").length > 8) {
log.get(0).removeChild(log.children("li")[0]);
}
}
function getTime() {
var now= new Date(),
h=now.getHours(),
m=now.getMinutes(),
s=now.getSeconds(),
ms=now.getMilliseconds();
return (h+":"+m+":"+s+ " " +ms);
}
function refreshNode(e) {
var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
type = e.data.type,
silent = e.data.silent,
nodes = zTree.getSelectedNodes();
if (nodes.length == 0) {
alert("请先选择一个父节点");
}
for (var i=0, l=nodes.length; i<l; i++) {
zTree.reAsyncChildNodes(nodes[i], type, silent);
if (!silent) zTree.selectNode(nodes[i]);
}
}
$(document).ready(function(){
$.fn.zTree.init($("#treeDemo"), setting);
$("#refreshNode").bind("click", {type:"refresh", silent:false}, refreshNode);
$("#refreshNodeSilent").bind("click", {type:"refresh", silent:true}, refreshNode);
$("#addNode").bind("click", {type:"add", silent:false}, refreshNode);
$("#addNodeSilent").bind("click", {type:"add", silent:true}, refreshNode);
});
//-->
</SCRIPT>
</HEAD>
<BODY>
<h1>用 zTree 方法异步加载节点数据</h1>
<h6>[ 文件路径: core/async_fun.html ]</h6>
<div class="content_wrap">
<div class="zTreeDemoBackground left">
<ul id="treeDemo" class="ztree"></ul>
</div>
<div class="right">
<ul class="info">
<li class="title"><h2>1、reAsyncChildNodes 方法操作说明</h2>
<ul class="list">
<li class="highlight_red">使用 zTreeObj.reAsyncChildNodes 方法,详细请参见 API 文档中的相关内容</li>
<li><p>此 Demo 只能同时选中一个父节点<br/>
试试看:[ <a id="refreshNode" href="#" onclick="return false;">重新加载</a> ] [ <a id="addNode" href="#" onclick="return false;">追加</a> ]</p>
</li>
<li><p><span class="highlight_red">“悄悄地”操作只能针对 折叠状态 的父节点</span><br/>
试试看:[ <a id="refreshNodeSilent" href="#" onclick="return false;">悄悄地 重新加载</a> ] [ <a id="addNodeSilent" href="#" onclick="return false;">悄悄地 追加</a> ]<br/>
async log:<br/>
<ul id="log" class="log"></ul></p>
</li>
</ul>
</li>
<li class="title"><h2>2、setting 配置信息说明</h2>
<ul class="list">
<li class="highlight_red">使用 zTree 提供的 reAsyncChildNodes 方法也必须设置 setting.async 中的各个属性,详细请参见 API 文档中的相关内容</li>
</ul>
</li>
<li class="title"><h2>3、treeNode 节点数据说明</h2>
<ul class="list">
<li>同 "异步加载 节点数据" 中的说明</li>
</ul>
</li>
<li class="title"><h2>4、其他说明</h2>
<ul class="list">
<li>同 "异步加载 节点数据" 中的说明</li>
</ul>
</li>
</ul>
</div>
</div>
</BODY>
</HTML>