如果父节点对于树是未知的,是否可以加载,然后选择一个子节点?

问题描述

我正在使用jsTree作为导航器,供用户选择显示在另一个窗格中的不同项目。到目前为止,一切都按预期进行,除非用户(从另一个窗格中)选择了尚未加载到树中的项目。

树目前正在从AJAX获取所有数据。

我尝试使用open_node()load_node()函数,但是如果未加载父节点,它们将无效。

我的问题:如果父节点对于树是未知的,是否可以加载,然后选择一个子节点?如果没有,是否有任何变通办法可以达到类似的效果

编辑:

树初始化器:

    $('#jsTree-Location').jstree({
    "core": {
        "animation": 0,"check_callback": true,"themes": {
            "stripes": true,"icons": true
        },"data": {
            'url': '@Url.Action("LocationList","Location")','type': 'GET','dataType': 'JSON','contentType': 'application/json','data': function (node) {
                return { sID: node.id,sType: node.type };
            }
        }
    },"json_data": {},"plugins": [
        "contextmenu","dnd","search","state","wholerow","types"
    ],"state": { "key": "system" },"contextmenu": { items: customMenu },"types": {
        "default": {
            "icon": "glyphicon glyphicon-flash"
        },"location": {
            "icon": "fas fa-map-marker-alt"
        },"asset": {
            "icon": "fa fa-cube"
        },"link": {
            "icon": "fa fa-cube"
        },"system": {
            "icon": "fas fa-cogs"
        }
    }
}})

用户“从外部”选择节点时调用函数

    function displayAsset(id) {
    ShowSpinner($("#window"),"Loading Asset...");

    //If Location Tree is active,activate the Asset in it.
    var sysTree = $('#jsTree-Location').jstree().get_selected()[0]
    if (typeof sysTree !== "undefined") {
        $("#jsTree-Location").jstree().open_node(['#asset-' + id,'#link-' + id],function (node,status) {
            if (status) {
                $("#jsTree-Location").jstree().activate_node(node)
            }
        })

    }

    //AJAX call to get Asset partial display
    $.ajax({
        url: '/Assets/_AssetEdit/',type: 'GET',data: {
            'id': id
        },success: function (html) {
            HideSpinner($("#window"));
            $("#window").html(html)
            BuildTable();
        }
    })
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)