在树加载完成后,将jsTree中的Three_state属性的值更改为复选框补的true。

时间:2019-06-06 18:26:19

标签: jquery jstree

在jsTree中,我使用复选框补码及其以下的three_state属性进行以下操作: 否,但是我想在数据加载完成时更新属性 three_state为true,请查看文档,而我仅找到如何更新树的数据,而不是补数的属性。 我正在尝试这样做,但是不起作用

    $.ajax({
                async: true,
                type: "POST",
                url: "/Perfiles/GetTreeData",
                dataType: "json",
                success: function (data) {
                    createJSTrees(data);
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert(xhr.status);
                    alert(thrownError);
                },
                complete: function () {
                    $('#onflycheckboxes').jstree({
                       checkbox: {
                          three_state: true
                       },
                      plugins: ["themes", "types", "json_data", "ui", 
                      "checkbox", "children"]
                   })

                }
            });


  function createJSTrees(jsondata) {
            $('#onflycheckboxes').jstree({
                'core': {
                    'data': jsondata,
                    "check_callback": true
                },
                "types": {
                    "default": {
                        "icon": "fa fa-folder"
                    },
                },
                checkbox: {
                    keep_selected_style: true,
                    three_state: true
                },
                "children": [{
                    "state": { "selected": true },
                    "icon": "fa fa-file"
                }],
                plugins: ["themes", "types", "json_data", "ui", 
                      "checkbox", "children"]
            });
        }

1 个答案:

答案 0 :(得分:0)

您需要将true传递给jstree函数以获取树的现有实例。在此实例上,您可以更新树的属性。

$('#onflycheckboxes').jstree(true).checkbox.three_state = true;