nexus site path corrected
[portal.git] / ecomp-portal-FE / client / bower_components / jqTree / _entries / 47_loaddata.md
1 ---
2 title: loadData
3 name: functions-loaddata
4 ---
5
6 **function loadData(data);**
7
8 **function loadData(data, parent_node);**
9
10 Load data in the tree. The data is array of nodes.
11
12 You can **replace the whole tree** or you can **load a subtree**.
13
14 {% highlight js %}
15 // Assuming the tree exists
16 var new_data = [
17     {
18         name: 'node1',
19         children: [
20             { name: 'child1' },
21             { name: 'child2' }
22         ]
23     },
24     {
25         name: 'node2',
26         children: [
27             { name: 'child3' }
28         ]
29     }
30 ];
31 $('#tree1').tree('loadData', new_data);
32 {% endhighlight %}
33
34 Load a subtree:
35
36 {% highlight js %}
37 // Get node by id (this assumes that the nodes have an id)
38 var node = $('#tree1').tree('getNodeById', 100);
39
40 // Add new nodes
41 var data = [
42     { name: 'new node' },
43     { name: 'another new node' }
44 ];
45 $('#tree1').tree('loadData', data, node);
46 {% endhighlight %}