【问题标题】:jsTree expand a node using AJAX call is not workingjsTree使用AJAX调用扩展节点不起作用
【发布时间】:2019-05-16 06:03:44
【问题描述】:

我正在使用jstree 并尝试在进行 AJAX 调用时扩展父节点。

我尝试按照文档进行操作,但无法正常工作..

                                        _panelContent.jstree({'core': {
                                            'url': function (node) {
                                                console.log('Node', node);
                                                var url = '/mystorage/directory?resourcename=' + node.text;

                                                return url;
                                            },
                                            'data': function () { // loop through the response and push them in data
                                                var results = [];
                                                for (var i = 0; i < _result.length; i++) {
                                                    results.push({ id: i, text: _result[i].name, state: 'closed' });
                                                }

                                                return results;
                                            }

                                        } });

我做错了什么?

只有加载图标出现....但呼叫永远不会解决..呼叫也不会通过网络。

但如果我硬编码完整的 url 并在不进行 AJAX 调用的情况下进行加载,jstree 会正确呈现。

【问题讨论】:

标签: javascript jquery jstree


【解决方案1】:

您的jstree ajax 调用配置不正确。有很多方法可以做到这一点

一种方式可能是

jQuery("#introspection_tree").jstree({
    "plugins" : ["themes", "json_data", "ui"],
    "json_data" : {
        "ajax" : {
            "type": 'GET',
            "url": function (node) {
                var nodeId = "";
                var url = ""
                if (node == -1)
                {
                    url = "http://localhost/introspection/introspection/product/";
                }
                else
                {
                    nodeId = node.attr('id');
                    url = "http://localhost/introspection/introspection/children/" + nodeId;
                }

                return url;
            },
            "success": function (new_data) {
                return new_data;
            }
        }
    }
});

这只是展示如何调用 ajax 调用的方式。

更多细节here接受的答案

【讨论】:

    猜你喜欢
    • 2013-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多