【问题标题】:Change AJAX options in jstree AND reload the tree from server更改 jstree 中的 AJAX 选项并从服务器重新加载树
【发布时间】:2011-06-29 11:16:22
【问题描述】:

我正在使用 ajax 在我的 jsTree 中加载 XML 平面树,所以声明看起来像这样(它工作正常):

  $("#jstree").jstree({
        "xml_data": {
            //  "data": $xmlFlatData,
            "ajax": {
                type: "POST",
                async: true,
                "url": loc + "/AjaxReturnTree",
                data: '{"longnames":"'+flag+'"}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                cache: false,
                success: function (msg) { 
                        var mm = eval('(' + msg + ')'); ; // create object to get rid of json
                        return mm.d;
                },
                error: function () {
                    // TODO process error
                }
            },
            "xsl": "flat",
            "override_ui": "true",
            "real_checkboxes": "true"
        },
        "plugins": ["xml_data", "themes", "checkbox", "ui"]
    });

现在我需要重新加载树并将“longnames”部分更改为另一个标志(它是 0/1),但保持其他选项不变。

我正在尝试使用这样的东西:

           $("#jstree").jstree({
                "xml_data": {
                    "ajax": {
                     cache: false,
                        data: '{"longnames":"' + flag + '"}'
                    }
                }
            });
            $("#jstree").jstree("refresh");

但它不会触发新的 AJAX 请求,只会刷新屏幕上的树而不重新加载。

如何让树从服务器重新加载?

另外,我如何确定我更改了旧 ajax 设置的属性,而不是创建一个全新的树对象?

【问题讨论】:

    标签: jquery jstree


    【解决方案1】:
    标志 = 0; 函数获取数据(){ return '{"longnames":"' + flag + '"}'; } $("#jstree").jstree({ “xml_data”:{ “阿贾克斯”:{ 缓存:假, 数据:获取数据() } } }); $("#jstree").jstree("刷新"); //刷新标志= 0 标志 = 1; $("#jstree").jstree("刷新"); //刷新标志= 1

    【讨论】:

      【解决方案2】:

      应该删除 "data:getData" 的括号 或者,jQuery 将执行 getData() 并只保留第一次执行的结果。 如果没有括号,jQuery 会将“数据”的值作为函数进行交易,并且每次都运行它。 顺便说一句,当心“cache: false”,jQuery 将发布“_”cacheBurster。

      【讨论】:

        猜你喜欢
        • 2014-10-13
        • 1970-01-01
        • 2016-06-27
        • 1970-01-01
        • 2014-07-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多