summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-FE/client/bower_components/jqTree/_entries/38_appendnode.md
blob: 2eeea2848f4370cb5adf68881e33276e6e0939b6 (plain)
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
---
title: appendNode
name: functions-appendnode
---

**function appendNode(new_node_info, parent_node);**

Add a node to this parent node. If **parent_node** is empty, then the new node becomes a root node.

{% highlight js %}
var parent_node = $tree.tree('getNodeById', 123);

$tree.tree(
    'appendNode',
    {
        name: 'new_node',
        id: 456
    },
    parent_node
);
{% endhighlight %}

To add a root node, leave *parent_node* empty:

{% highlight js %}
$tree.tree(
    'appendNode',
    {
        name: 'new_node',
        id: 456
    }
);
{% endhighlight %}

It's also possible to append a subtree:

{% highlight js %}
$tree.tree(
    'appendNode',
    {
        name: 'new_node',
        id: 456,
        children: [
            { name: 'child1', id: 457 },
            { name: 'child2', id: 458 }
        ]
    },
    parent_node
);
{% endhighlight %}