javascript - jsTree (3.x) ajax config handlers runs only once? -


i read documentation how setup ajax data source jstree component. don't understand following code:

        'data': {             'url': function (node) {                 return '/ajax/test-nodes';             },             'data': function (node) {                 return {'id': node.id};             }         } 

1) why need use function 'url', how advantages gives?

2) why 'url' , 'data' handlers runs 1 time(i use console.log check it), despite ajax response contains many nodes:

[{"id":1,"parent":"#","text":"n1"},{"id":2,"parent":"#","text":"n2"},{"id":3,"parent":"1","text":"child of n1"},{"id":4,"parent":"1","text":"child of n1"},{"id":5,"parent":"3","text":"subchild of n1"}] 

3) value need return functions ('url', 'data') ?

thanks lot!

it pretty clear in docs of config option:

in addition standard jquery ajax options here can suppy functions data , url, functions run in current instance's scope , param passed indicating node being loaded, return value of functions used.

it explained here in repository:

first off data config option of core.data object. if check jquery, supposed string or object. jstree makes possible set function. each time jstree needs make ajax call function called , receive single parameter - node being loaded. return value of function used actual "data" of ajax call. understand better open demo , see requests go off in console.

...

you can set url function , works data - each time request has made, jstree invoke function , request go off whatever return in function. useful when dealing urls like: http://example.com/get_children/1

read above links familiar lazy loading , how use - there many examples.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -