在点击父节点(json)后加载子节点

Jstree - load child nodes after clicking on parent (json)

本文关键字:加载 子节点 json 父节点      更新时间:2023-09-26

我想在单击父节点后加载父节点的子节点。因为有很多孩子,这是保持高性能的唯一方法。

现在我得到了这个

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

对于第一级来说很好。现在我想从这个URL

获取子节点

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

我不知道如何才能做到这一点?

编辑:服务GetCountryList生成了如下内容:

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

和GetRegionList

像这样:

[{"id":"SH","parent":"DE","state":"closed","text":"SH"},
{"id":"NRW","parent":"DE","state":"closed","text":"NRW"},
{"id":"LON","parent":"GBR","state":"closed","text":"LON"}]

使用

$(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"
            }
        }
    });
});