summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-FE/client/bower_components/jqTree/_entries/07_tutorial.md
blob: 55fe21e0ece47750942b52a7a39f708ab4c94938 (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
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
---
title: Tutorial
name: Tutorial
---

Include [jQuery](http://code.jquery.com/jquery.min.js)

{% highlight html %}
<script src="jquery.min.js"></script>
{% endhighlight %}

Include tree.jquery.js:

{% highlight html %}
<script src="tree.jquery.js"></script>
{% endhighlight %}

Include jqtree.css:

{% highlight html %}
<link rel="stylesheet" href="jqtree.css">
{% endhighlight %}

Optionally, for saveState include [jquery-cookie](https://github.com/carhartl/jquery-cookie):

{% highlight html %}
<script src="jquery.cookie.js"></script>
{% endhighlight %}

Create a div.

{% highlight html %}
<div id="tree1"></div>
{% endhighlight %}

Create tree data.

{% highlight js %}
var data = [
    {
        name: 'node1',
        children: [
            { name: 'child1' },
            { name: 'child2' }
        ]
    },
    {
        name: 'node2',
        children: [
            { name: 'child3' }
        ]
    }
];
{% endhighlight %}

Create tree widget.

{% highlight js %}
$(function() {
    $('#tree1').tree({
        data: data
    });
});
{% endhighlight %}

Alternatively, get the data from the server.

{% highlight js %}
$.getJSON(
    '/some_url/',
    function(data) {
        $('#tree1').tree({
            data: data
        });
    }
);
{% endhighlight %}