2

I want to load the child nodes of a parent node after clicking on the parent node. Because there are many childs this is the only way to keep the performance high.

Now I got this

$(function () {
    $.support.cors = true;
    $('#using_json').jstree({
        "plugins": ["themes", "json_data", "dnd", "wholerow"],
            'core': {
            'data': {
                'url': "http://localhost:56311/ProductRESTService.svc/GetCountryList",
                    'dataType': "json"
            }
        }
    });
});

this works fine for the first level. Now I want to get the childs from this URL

"http://localhost:56311/ProductRESTService.svc/GetRegionList/{id}",

I do not know how I can achieve this?

edit: The service GetCountryList generated something like this:

[{"id":"DE","parent":"#","state":"closed","text":"DE"},
{"id":"GBR","parent":"#","state":"closed","text":"GBR"},
{"id":"SE","parent":"#","state":"closed","text":"SE"}]

and GetRegionList

something like this:

[{"id":"SH","parent":"DE","state":"closed","text":"SH"},
{"id":"NRW","parent":"DE","state":"closed","text":"NRW"},
{"id":"LON","parent":"GBR","state":"closed","text":"LON"}]
  • Are you talking about how to do: `var myid = '123'; var url = "http://localhost:56311/ProductRESTService.svc/GetRegionList/" + myid;` or can you clarify your question a bit regarding you intent? – Mark Schultheiss Aug 24 '15 at 12:17
  • Take a look here http://stackoverflow.com/questions/24131181/lazy-loading-with-jstree and here http://stackoverflow.com/questions/22627132/jstree-load-nodes-dynamically I guess it is what you need. – fdam Aug 24 '15 at 12:24

1 Answers1

3

Use this:

$(function () {
    $.support.cors = true;
    $('#using_json').jstree({
        "plugins": ["themes", "json_data", "dnd", "wholerow"],
            'core': {
            'data': {
                'url': function (node) {
                    if(node.id === '#') {
                        return "http://localhost:56311/ProductRESTService.svc/GetCountryList";
                    }
                    else {
                        return "http://localhost:56311/ProductRESTService.svc/GetRegionList/" + node.id;
                    }
                },
                'dataType': "json"
            }
        }
    });
});
vakata
  • 3,726
  • 1
  • 17
  • 31
  • Hello thanks for your help I tried this and than I get the parent nodes but nothing happens when I click on them there are no child nodes I wrote my json files in the first post maybe the error is there. Thank you – Pascal Homberg Aug 25 '15 at 05:18
  • 1
    Thank you it helped a lot this works fine when I add the boolean paramater children to the nodes. Thank you – Pascal Homberg Aug 25 '15 at 05:23
  • Note that, on parent nodes, you need to have children = true for the 2nd ajax call to work – Jaber Al Nahian Jul 26 '18 at 09:46