forked from cocoo/easyui-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree.html
679 lines (635 loc) · 33.4 KB
/
tree.html
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>tree</title>
<link rel="stylesheet" type="text/css" href="css/main.css" />
<link rel="stylesheet" type="text/css" href="css/SyntaxHighlighter.css" />
<script type="text/javascript" src="js/shCore.js"></script>
<script type="text/javascript" src="js/shBrushJScript.js"></script>
<script type="text/javascript" src="js/shBrushXml.js"></script>
</head>
<body style="text-align:left">
<div style="padding:10px">
<h3>Tree</h3>
<p>Override defaults with $.fn.tree.defaults.</p>
<p>
The tree displays hierarchical data in a tree structure in a web page.
It provides users expand, collapse, drag and drop, editing and async loading functionality.
</p>
<img src="images/tree.png">
<h4>Dependencies</h4>
<ul>
<li>draggable</li>
<li>droppable</li>
</ul>
<h4>Usage Example</h4>
<p>
Tree can be definded in <ul> element.
The markup can defines leaf and children. The nodes will be <li> elements within ul list.
The following shows the elements that will be used to make the tree node nested within the ul elements.
</p>
<div class="dp-highlighter"><div class="bar"><div class="tools"></div></div><ol start="1" class="dp-xml"><li class="alt"><span><span class="tag"><</span><span class="tag-name">ul</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">"tt"</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"easyui-tree"</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"><</span><span class="tag-name">li</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"><</span><span class="tag-name">span</span><span class="tag">></span><span>Folder</span><span class="tag"></</span><span class="tag-name">span</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"><</span><span class="tag-name">ul</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"><</span><span class="tag-name">li</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"><</span><span class="tag-name">span</span><span class="tag">></span><span>Sub Folder 1</span><span class="tag"></</span><span class="tag-name">span</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"><</span><span class="tag-name">ul</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"><</span><span class="tag-name">li</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"><</span><span class="tag-name">span</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">a</span><span> </span><span class="attribute">href</span><span>=</span><span class="attribute-value">"#"</span><span class="tag">></span><span>File 11</span><span class="tag"></</span><span class="tag-name">a</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">span</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"></</span><span class="tag-name">li</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"><</span><span class="tag-name">li</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"><</span><span class="tag-name">span</span><span class="tag">></span><span>File 12</span><span class="tag"></</span><span class="tag-name">span</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"></</span><span class="tag-name">li</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"><</span><span class="tag-name">li</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"><</span><span class="tag-name">span</span><span class="tag">></span><span>File 13</span><span class="tag"></</span><span class="tag-name">span</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"></</span><span class="tag-name">li</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"></</span><span class="tag-name">ul</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"></</span><span class="tag-name">li</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"><</span><span class="tag-name">li</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"><</span><span class="tag-name">span</span><span class="tag">></span><span>File 2</span><span class="tag"></</span><span class="tag-name">span</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"></</span><span class="tag-name">li</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"><</span><span class="tag-name">li</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"><</span><span class="tag-name">span</span><span class="tag">></span><span>File 3</span><span class="tag"></</span><span class="tag-name">span</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"></</span><span class="tag-name">li</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"></</span><span class="tag-name">ul</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"></</span><span class="tag-name">li</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"><</span><span class="tag-name">li</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"><</span><span class="tag-name">span</span><span class="tag">></span><span>File21</span><span class="tag"></</span><span class="tag-name">span</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"></</span><span class="tag-name">li</span><span class="tag">></span><span> </span></span></li><li class=""><span><span class="tag"></</span><span class="tag-name">ul</span><span class="tag">></span><span> </span></span></li></ol></div><textarea class="html" name="code-tree" style="display: none;"> <ul id="tt" class="easyui-tree">
<li>
<span>Folder</span>
<ul>
<li>
<span>Sub Folder 1</span>
<ul>
<li>
<span><a href="#">File 11</a></span>
</li>
<li>
<span>File 12</span>
</li>
<li>
<span>File 13</span>
</li>
</ul>
</li>
<li>
<span>File 2</span>
</li>
<li>
<span>File 3</span>
</li>
</ul>
</li>
<li>
<span>File21</span>
</li>
</ul>
</textarea>
<p>Tree can also be defined in an empty <ul> element and load data using javascript.</p>
<div class="dp-highlighter"><div class="bar"><div class="tools"></div></div><ol start="1" class="dp-xml"><li class="alt"><span><span class="tag"><</span><span class="tag-name">ul</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">"tt"</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">ul</span><span class="tag">></span><span> </span></span></li></ol></div><textarea class="html" name="code-tree" style="display: none;"> <ul id="tt"></ul>
</textarea>
<div class="dp-highlighter"><div class="bar"><div class="tools"></div></div><ol start="1" class="dp-c"><li class="alt"><span><span>$(</span><span class="string">'#tt'</span><span>).tree({ </span></span></li><li class=""><span> url:<span class="string">'tree_data.json'</span><span> </span></span></li><li class="alt"><span>}); </span></li></ol></div><textarea class="js" name="code-tree" style="display: none;"> $('#tt').tree({
url:'tree_data.json'
});
</textarea>
<p>Use loadFilter to process the json data from ASP.NET web services.</p>
<div class="dp-highlighter"><div class="bar"><div class="tools"></div></div><ol start="1" class="dp-c"><li class="alt"><span><span>$(</span><span class="string">'#tt'</span><span>).tree({ </span></span></li><li class=""><span> url: ..., </span></li><li class="alt"><span> loadFilter: <span class="keyword">function</span><span>(data){ </span></span></li><li class=""><span> <span class="keyword">if</span><span> (data.d){ </span></span></li><li class="alt"><span> <span class="keyword">return</span><span> data.d; </span></span></li><li class=""><span> } <span class="keyword">else</span><span> { </span></span></li><li class="alt"><span> <span class="keyword">return</span><span> data; </span></span></li><li class=""><span> } </span></li><li class="alt"><span> } </span></li><li class=""><span>}); </span></li></ol></div><textarea class="js" name="code-tree" style="display: none;"> $('#tt').tree({
url: ...,
loadFilter: function(data){
if (data.d){
return data.d;
} else {
return data;
}
}
});
</textarea>
<br>
<h4>Tree Data Format</h4>
<p>Every node can contains following properties:</p>
<ul>
<li>id: node id, which is important to load remote data</li>
<li>text: node text to show</li>
<li>state: node state, 'open' or 'closed', default is 'open'. When set to 'closed', the node have children nodes and will load them from remote site</li>
<li>checked: Indicate whether the node is checked selected.</li>
<li>attributes: custom attributes can be added to a node</li>
<li>children: an array nodes defines some children nodes</li>
</ul>
<p>Some example:</p>
<div class="dp-highlighter"><div class="bar"><div class="tools"></div></div><ol start="1" class="dp-c"><li class="alt"><span><span>[{ </span></span></li><li class=""><span> <span class="string">"id"</span><span>:1, </span></span></li><li class="alt"><span> <span class="string">"text"</span><span>:</span><span class="string">"Folder1"</span><span>, </span></span></li><li class=""><span> <span class="string">"iconCls"</span><span>:</span><span class="string">"icon-save"</span><span>, </span></span></li><li class="alt"><span> <span class="string">"children"</span><span>:[{ </span></span></li><li class=""><span> <span class="string">"text"</span><span>:</span><span class="string">"File1"</span><span>, </span></span></li><li class="alt"><span> <span class="string">"checked"</span><span>:</span><span class="keyword">true</span><span> </span></span></li><li class=""><span> },{ </span></li><li class="alt"><span> <span class="string">"text"</span><span>:</span><span class="string">"Books"</span><span>, </span></span></li><li class=""><span> <span class="string">"state"</span><span>:</span><span class="string">"open"</span><span>, </span></span></li><li class="alt"><span> <span class="string">"attributes"</span><span>:{ </span></span></li><li class=""><span> <span class="string">"url"</span><span>:</span><span class="string">"/demo/book/abc"</span><span>, </span></span></li><li class="alt"><span> <span class="string">"price"</span><span>:100 </span></span></li><li class=""><span> }, </span></li><li class="alt"><span> <span class="string">"children"</span><span>:[{ </span></span></li><li class=""><span> <span class="string">"text"</span><span>:</span><span class="string">"PhotoShop"</span><span>, </span></span></li><li class="alt"><span> <span class="string">"checked"</span><span>:</span><span class="keyword">true</span><span> </span></span></li><li class=""><span> },{ </span></li><li class="alt"><span> <span class="string">"id"</span><span>: 8, </span></span></li><li class=""><span> <span class="string">"text"</span><span>:</span><span class="string">"Sub Bookds"</span><span>, </span></span></li><li class="alt"><span> <span class="string">"state"</span><span>:</span><span class="string">"closed"</span><span> </span></span></li><li class=""><span> }] </span></li><li class="alt"><span> }] </span></li><li class=""><span>},{ </span></li><li class="alt"><span> <span class="string">"text"</span><span>:</span><span class="string">"Languages"</span><span>, </span></span></li><li class=""><span> <span class="string">"state"</span><span>:</span><span class="string">"closed"</span><span>, </span></span></li><li class="alt"><span> <span class="string">"children"</span><span>:[{ </span></span></li><li class=""><span> <span class="string">"text"</span><span>:</span><span class="string">"Java"</span><span> </span></span></li><li class="alt"><span> },{ </span></li><li class=""><span> <span class="string">"text"</span><span>:</span><span class="string">"C#"</span><span> </span></span></li><li class="alt"><span> }] </span></li><li class=""><span>}] </span></li></ol></div><textarea class="js" name="code-tree" style="display: none;"> [{
"id":1,
"text":"Folder1",
"iconCls":"icon-save",
"children":[{
"text":"File1",
"checked":true
},{
"text":"Books",
"state":"open",
"attributes":{
"url":"/demo/book/abc",
"price":100
},
"children":[{
"text":"PhotoShop",
"checked":true
},{
"id": 8,
"text":"Sub Bookds",
"state":"closed"
}]
}]
},{
"text":"Languages",
"state":"closed",
"children":[{
"text":"Java"
},{
"text":"C#"
}]
}]
</textarea>
<br>
<h4>The Async Tree</h4>
<p>
The tree supports the built-in async loading mode, with which users create an empty tree,
then specify a server side that dynamically returns the JSON data to use to populate the tree with asynchronously and on demand.
Here is an example:
</p>
<div class="dp-highlighter"><div class="bar"><div class="tools"></div></div><ol start="1" class="dp-xml"><li class="alt"><span><span class="tag"><</span><span class="tag-name">ul</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"easyui-tree"</span><span> </span><span class="attribute">data-options</span><span>=</span><span class="attribute-value">"url:'get_data.php'"</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">ul</span><span class="tag">></span><span> </span></span></li></ol></div><textarea class="html" name="code-tree" style="display: none;"> <ul class="easyui-tree" data-options="url:'get_data.php'"></ul>
</textarea>
<p>
The tree is loaded with the URL 'get_data.php'.
The child nodes to be loaded dependent on the parent node state.
When expand a closed node, if the node has no child nodes loaded,
it will send node id value as the http request parameter named 'id' to server via the URL defined above to retrieve child nodes.
</p>
<p>Looks at the data returned from server:</p>
<div class="dp-highlighter"><div class="bar"><div class="tools"></div></div><ol start="1" class="dp-c"><li class="alt"><span><span>[{ </span></span></li><li class=""><span> <span class="string">"id"</span><span>: 1, </span></span></li><li class="alt"><span> <span class="string">"text"</span><span>: </span><span class="string">"Node 1"</span><span>, </span></span></li><li class=""><span> <span class="string">"state"</span><span>: </span><span class="string">"closed"</span><span>, </span></span></li><li class="alt"><span> <span class="string">"children"</span><span>: [{ </span></span></li><li class=""><span> <span class="string">"id"</span><span>: 11, </span></span></li><li class="alt"><span> <span class="string">"text"</span><span>: </span><span class="string">"Node 11"</span><span> </span></span></li><li class=""><span> },{ </span></li><li class="alt"><span> <span class="string">"id"</span><span>: 12, </span></span></li><li class=""><span> <span class="string">"text"</span><span>: </span><span class="string">"Node 12"</span><span> </span></span></li><li class="alt"><span> }] </span></li><li class=""><span>},{ </span></li><li class="alt"><span> <span class="string">"id"</span><span>: 2, </span></span></li><li class=""><span> <span class="string">"text"</span><span>: </span><span class="string">"Node 2"</span><span>, </span></span></li><li class="alt"><span> <span class="string">"state"</span><span>: </span><span class="string">"closed"</span><span> </span></span></li><li class=""><span>}] </span></li></ol></div><textarea class="js" name="code-tree" style="display: none;"> [{
"id": 1,
"text": "Node 1",
"state": "closed",
"children": [{
"id": 11,
"text": "Node 11"
},{
"id": 12,
"text": "Node 12"
}]
},{
"id": 2,
"text": "Node 2",
"state": "closed"
}]
</textarea>
<p>
The node 1 and node 2 are closed, when expand the node 1, it will directly show its child nodes.
When expand node 2, it will send the value(2) to server to retrieve child nodes.
</p>
<p>
This tutorial
<a target="_blank" href="../tutorial/tree/tree2.php">Create Async Tree</a>
shows how to write server code to return the tree data on demand.
</p>
<h4>Properties</h4>
<table class="doc-table">
<tbody><tr>
<th><strong>Name</strong></th>
<th><strong>Type</strong></th>
<th><strong>Description</strong></th>
<th><strong>Default</strong></th>
</tr>
<tr>
<td>url</td>
<td>string</td>
<td>a URL to retrieve remote data.</td>
<td>null</td>
</tr>
<tr>
<td>method</td>
<td>string</td>
<td>The http method to retrieve data.</td>
<td>post</td>
</tr>
<tr>
<td>animate</td>
<td>boolean</td>
<td>Defines if to show animation effect when node expand or collapse.</td>
<td>false</td>
</tr>
<tr>
<td>checkbox</td>
<td>boolean</td>
<td>Defines if to show the checkbox before every node.</td>
<td>false</td>
</tr>
<tr>
<td>cascadeCheck</td>
<td>boolean</td>
<td>Defines if to cascade check.</td>
<td>true</td>
</tr>
<tr>
<td>onlyLeafCheck</td>
<td>boolean</td>
<td>Defines if to show the checkbox only before leaf node.</td>
<td>false</td>
</tr>
<tr>
<td>lines</td>
<td>boolean</td>
<td>Defines if to show tree lines.</td>
<td>false</td>
</tr>
<tr>
<td>dnd</td>
<td>boolean</td>
<td>Defines if to enable drag and drop.</td>
<td>false</td>
</tr>
<tr>
<td>data</td>
<td>array</td>
<td>
The node data to be loaded.
<pre>$('#tt').tree({
data: [{
text: 'Item1',
state: 'closed',
children: [{
text: 'Item11'
},{
text: 'Item12'
}]
},{
text: 'Item2'
}]
});
</pre>
</td>
<td>null</td>
</tr>
<tr>
<td>loader</td>
<td>function(param,success,error)</td>
<td>
Defines how to load data from remote server. Return false can abort this action.
This function takes the following parameters:<br>
param: the parameter object to pass to remote server.<br>
success(data): the callback function that will be called when retrieve data successfully.<br>
error(): the callback function that will be called when failed to retrieve data.
</td>
<td>json loader</td>
</tr>
<tr>
<td>loadFilter</td>
<td>function(data,parent)</td>
<td>
Return the filtered data to display. The returned data is in standard tree format.
This function takes the following parameters:<br>
data: the original data to be loaded.<br>
parent: DOM object, indicate the parent node.
</td>
<td></td>
</tr>
</tbody></table>
<h4>Events</h4>
<p>Many events callback function can take the 'node' parameter, which contains following properties:</p>
<ul>
<li>id: An identity value bind to the node.</li>
<li>text: Text to be showed.</li>
<li>iconCls: The css class to display icon.</li>
<li>checked: Whether the node is checked.</li>
<li>state: The node state, 'open' or 'closed'.</li>
<li>attributes: Custom attributes bind to the node.</li>
<li>target: Target DOM object.</li>
</ul>
<table class="doc-table">
<tbody><tr>
<th><strong>Name</strong></th>
<th><strong>Parameters</strong></th>
<th><strong>Description</strong></th>
</tr>
<tr>
<td>onClick</td>
<td>node</td>
<td>
Fires when user click a node. Code example:
<pre style="color:#006600">$('#tt').tree({
onClick: function(node){
alert(node.text); // alert node text property when clicked
}
});
</pre>
</td>
</tr>
<tr>
<td>onDblClick</td>
<td>node</td>
<td>Fires when user dblclick a node.</td>
</tr>
<tr>
<td>onBeforeLoad</td>
<td>node, param</td>
<td>Fires before a request is made to load data, return false to cancel this load action.</td>
</tr>
<tr>
<td>onLoadSuccess</td>
<td>node, data</td>
<td>Fires when data loaded successfully.</td>
</tr>
<tr>
<td>onLoadError</td>
<td>arguments</td>
<td>Fires when data loaded fail, the arguments parameter is same as the 'error' function of jQuery.ajax.</td>
</tr>
<tr>
<td>onBeforeExpand</td>
<td>node</td>
<td>Fires before node is expanded, return false to cancel this expand action.</td>
</tr>
<tr>
<td>onExpand</td>
<td>node</td>
<td>Fires when node is expanded.</td>
</tr>
<tr>
<td>onBeforeCollapse</td>
<td>node</td>
<td>Fires before node is collapsed, return false to cancel this collapse action.</td>
</tr>
<tr>
<td>onCollapse</td>
<td>node</td>
<td>Fires when node is collapsed.</td>
</tr>
<tr>
<td>onCheck</td>
<td>node, checked</td>
<td>Fires when users click the checkbox.</td>
</tr>
<tr>
<td>onBeforeSelect</td>
<td>node</td>
<td>Fires before node is selected, return false to cancel this select action.</td>
</tr>
<tr>
<td>onSelect</td>
<td>node</td>
<td>Fires when node is selected.</td>
</tr>
<tr>
<td>onContextMenu</td>
<td>e, node</td>
<td>
Fires when node is right clicked. Code example:
<pre style="color:#006600">// right click node and then display the context menu
$('#tt').tree({
onContextMenu: function(e, node){
e.preventDefault();
// select the node
$('#tt').tree('select', node.target);
// display context menu
$('#mm').menu('show', {
left: e.pageX,
top: e.pageY
});
}
});
// the context menu is defined as below:
<div id="mm" class="easyui-menu" style="width:120px;">
<div onclick="append()" data-options="iconCls:'icon-add'">Append</div>
<div onclick="remove()" data-options="iconCls:'icon-remove'">Remove</div>
</div>
</pre>
</td>
</tr>
<tr>
<td>onDrop</td>
<td>target, source, point</td>
<td>Fires when a node is dropped.<br>
target: DOM object, The node being targeted for the drop.<br>
source: the source node.<br>
point: indicate the drop operation, posible values are: 'append','top' or 'bottom'.</td>
</tr>
<tr>
<td>onBeforeEdit</td>
<td>node</td>
<td>Fires before edit node.</td>
</tr>
<tr>
<td>onAfterEdit</td>
<td>node</td>
<td>Fires after edit node.</td>
</tr>
<tr>
<td>onCancelEdit</td>
<td>node</td>
<td>Fires when cancel the editing action.</td>
</tr>
</tbody></table>
<h4>Methods</h4>
<table class="doc-table">
<tbody><tr>
<th><strong>Name</strong></th>
<th><strong>Parameter</strong></th>
<th><strong>Description</strong></th>
</tr>
<tr>
<td>options</td>
<td>none</td>
<td>Return the options of tree.</td>
</tr>
<tr>
<td>loadData</td>
<td>data</td>
<td>Load the tree data.</td>
</tr>
<tr>
<td>getNode</td>
<td>target</td>
<td>get the specified node object.</td>
</tr>
<tr>
<td>getData</td>
<td>target</td>
<td>get the specified node data, including its children.</td>
</tr>
<tr>
<td>reload</td>
<td>target</td>
<td>Reload tree data.</td>
</tr>
<tr>
<td>getRoot</td>
<td>none</td>
<td>Get the root node, return node object</td>
</tr>
<tr>
<td>getRoots</td>
<td>none</td>
<td>Get the root nodes, return node array.</td>
</tr>
<tr>
<td>getParent</td>
<td>target</td>
<td>Get the parent node, the target parameter indicate the node DOM object.</td>
</tr>
<tr>
<td>getChildren</td>
<td>target</td>
<td>Get the children nodes, the target parameter indicate the node DOM object.</td>
</tr>
<tr>
<td>getChecked</td>
<td>none</td>
<td>Get all checked nodes.</td>
</tr>
<tr>
<td>getSelected</td>
<td>none</td>
<td>Get the selected node and return it, if no node selected return null.</td>
</tr>
<tr>
<td>isLeaf</td>
<td>target</td>
<td>Determine the specified node is leaf, the target parameter indicate the node DOM object.</td>
</tr>
<tr>
<td>find</td>
<td>id</td>
<td>
Find the specifed node and return the node object. Code example:
<pre style="color:#006600">// find a node and then select it
var node = $('#tt').tree('find', 12);
$('#tt').tree('select', node.target);
</pre>
</td>
</tr>
<tr>
<td>select</td>
<td>target</td>
<td>Select a node, the target parameter indicate the node DOM object.</td>
</tr>
<tr>
<td>check</td>
<td>target</td>
<td>Set the specified node to checked.</td>
</tr>
<tr>
<td>uncheck</td>
<td>target</td>
<td>Set the specified node to unchecked.</td>
</tr>
<tr>
<td>collapse</td>
<td>target</td>
<td>Collapse a node, the target parameter indicate the node DOM object.</td>
</tr>
<tr>
<td>expand</td>
<td>target</td>
<td>
Expand a node, the target parameter indicate the node DOM object.
When node is closed and has no child nodes,
the node id value(named as 'id' parameter) will be sent to server to request child nodes data.
</td>
</tr>
<tr>
<td>collapseAll</td>
<td>target</td>
<td>Collapse all nodes.</td>
</tr>
<tr>
<td>expandAll</td>
<td>target</td>
<td>Expand all nodes.</td>
</tr>
<tr>
<td>expandTo</td>
<td>target</td>
<td>Expand from root to specified node.</td>
</tr>
<tr>
<td>append</td>
<td>param</td>
<td>Append some children nodes to a parent node. param parameter has two properties:<br>
parent: DOM object, the parent node to append to, if not assigned, append as root nodes.<br>
data: array, the nodes data.
Code example:
<pre style="color:#006600">// append some nodes to the selected node
var selected = $('#tt').tree('getSelected');
$('#tt').tree('append', {
parent: selected.target,
data: [{
id: 23,
text: 'node23'
},{
text: 'node24',
state: 'closed',
children: [{
text: 'node241'
},{
text: 'node242'
}]
}]
});
</pre>
</td>
</tr>
<tr>
<td>toggle</td>
<td>target</td>
<td>Toggles expanded/collapsed state of the node, the target parameter indicate the node DOM object.</td>
</tr>
<tr>
<td>insert</td>
<td>param</td>
<td>Insert a node to before or after specified node. the 'param' parameter contains following properties:<br>
before: DOM object, the node to insert before.<br>
after: DOM object, the node to insert after.<br>
data: object, the node data.
<p>The code below shows how to insert a new node before the selected node:</p>
<pre>var node = $('#tt').tree('getSelected');
if (node){
$('#tt').tree('insert', {
before: node.target,
data: {
id: 21,
text: 'node text'
}
});
}
</pre>
</td>
</tr>
<tr>
<td>remove</td>
<td>target</td>
<td>Remove a node and it's children nodes, the target parameter indicate the node DOM object.</td>
</tr>
<tr>
<td>pop</td>
<td>target</td>
<td>Pop a node and it's children nodes, the method is same as remove but return the removed node data.</td>
</tr>
<tr>
<td>update</td>
<td>param</td>
<td>Update the specified node. The 'param' parameter has following properties:<br>
target(DOM object, the node to be updated),id,text,iconCls,checked,etc.
<p>Code example:</p>
<pre>// update the selected node text
var node = $('#tt').tree('getSelected');
if (node){
$('#tt').tree('update', {
target: node.target,
text: 'new text'
});
}
</pre>
</td>
</tr>
<tr>
<td>enableDnd</td>
<td>none</td>
<td>Enable drag and drop feature.</td>
</tr>
<tr>
<td>disableDnd</td>
<td>none</td>
<td>Disable drag and drop feature.</td>
</tr>
<tr>
<td>beginEdit</td>
<td>target</td>
<td>Begin editing a node.</td>
</tr>
<tr>
<td>endEdit</td>
<td>target</td>
<td>End editing a node.</td>
</tr>
<tr>
<td>cancelEdit</td>
<td>target</td>
<td>Cancel editing a node.</td>
</tr>
</tbody></table>
</div>
</body>
</html>