更改jstree中的AJAX选项并从服务器重新加载树 [英] Change AJAX options in jstree AND reload the tree from server

查看:68
本文介绍了更改jstree中的AJAX选项并从服务器重新加载树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ajax在jsTree中加载XML扁平树,因此声明看起来像这样(很好):

I am loading XML flat tree in my jsTree using ajax, so the declaration looks like this (it works fine):

  $("#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),但保持其他选项不变.

Now I need to reload the tree AND change the "longnames" part to another flag (it's either 0/1), but keep other options unchanged.

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

I am trying to use something like this:

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

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

But it does not trigger new AJAX request, only refreshes the tree on screen without reload.

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

How I can get tree to reload from server?

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

Also, how I can be sure that I change properties of old ajax setup, not creating a completely new tree object?

推荐答案


    flag = 0;

    function getData() {
        return '{"longnames":"' + flag + '"}';
    }

    $("#jstree").jstree({
        "xml_data": {
            "ajax": {
                cache: false,
                data: getData()
            }
        }
    });

    $("#jstree").jstree("refresh"); //refresh with flag = 0

    flag = 1;
    $("#jstree").jstree("refresh"); //refresh with flag = 1

这篇关于更改jstree中的AJAX选项并从服务器重新加载树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆