summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-FE/client/bower_components/jqTree/_entries/48_loaddatafromurl.md
blob: 3a005f316371c67d898fb499554a7168ae5ca780 (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
---
title: loadDataFromUrl
name: functions-loaddatafromurl
---

**function loadDataFromUrl(url);**

**function loadDataFromUrl(url, parent_node);**

**function loadDataFromUrl(parent_node);**

Load data in the tree from an url using ajax. You can **replace the whole tree** or you can **load a subtree**.

{% highlight js %}
$('#tree1').tree('loadDataFromUrl', '/category/tree/');
{% endhighlight %}

Load a subtree:

{% highlight js %}
var node = $('#tree1').tree('getNodeById', 123);
$('#tree1').tree('loadDataFromUrl', '/category/tree/123', node);
{% endhighlight %}

You can also omit the url. In this case jqTree will generate a url for you. This is very useful if you use the load-on-demand feature:

{% highlight js %}
var $tree = $('#tree1');

$tree.tree({
    dataUrl: '/my_data/'
});

var node = $tree.tree('getNodeById', 456);

// jqTree will load data from /my_data/?node=456
$tree.tree('loadDataFromUrl', node);
{% endhighlight %}

You can also add an **on_finished** callback parameter that will be called when the data is loaded:

**function loadDataFromUrl(url, parent_node, on_finished);**

**function loadDataFromUrl(parent_node, on_finished);**

{% highlight js %}
$('#tree1').tree(
    'loadDataFromUrl',
    '/category/tree/123',
    null,
    function() {
        alert('data is loaded');
    }
);
{% endhighlight %}