【问题标题】:How to load data checked on JsTree如何加载在 JsTree 上检查的数据
【发布时间】:2020-05-05 15:54:39
【问题描述】:

我想知道,如何在 JsTree 上加载新数据,我必须像这样在点击时加载数据:

 function showTree(group_id){
        $("#jstree").jstree({
            "core": {
                "themes": {
                    'name': 'proton',
                    'responsive': true
                },
                "data": {
                   type: "POST",
                   url: "/menu/tree",
                   dataType: "json",
                   data: {
                         group_id: group_id
                   },
                   success: function (data) {
                      data.d;
                      console.log(data);
                      $(data).each(function () {
                         return { "id": this.id };
                      });
                   }
                },
             },
            "checkbox" : {
                "keep_selected_style" : false
            },
            "plugins" : [ "checkbox" , "types", "json_data"]
        });
}

当我第一次调用函数时它的工作但第二次使用不同的数据时数据不会改变。

注意:不同的数据来自检查值

数据示例: 新:

   {
      id          : "1"
      text        : "Test 1"
      state       : {
        selected  : true
      },
    }
    {
      id          : "2"
      text        : "Test 2"
      state       : {
        selected  : false
      },
    }

我改成:

{
  id          : "1"
  text        : "Test 1"
  state       : {
    selected  : false
  },
}
{
  id          : "2"
  text        : "Test 2"
  state       : {
    selected  : false
  },
}

我可以只更改从 JsTree 中选择的数据吗?

【问题讨论】:

    标签: jquery jstree


    【解决方案1】:

    $("#jstree").jstree() 初始化jsTree 是一次性的,不能重复使用。再次对元素调用 jstree 函数可能不会重新创建树。如果您使用 ajax 来源的数据,您可以使用 jsTree 的函数重新绘制新数据。

    刷新功能可以从ajax url加载新数据。

    function updateTree(group_id){
        $("#jstree").jstree(true).settings.core.data = {
            type: "POST",
            url: "/menu/tree",
            dataType: "json",
            data: {
                 group_id: group_id
            },
            success: function (data) {
              data.d;
              console.log(data);
              $(data).each(function () {
                 return { "id": this.id };
              });
            }
        };
    
        $("#jstree").jstree(true).refresh();
    }
    

    【讨论】:

    • 如果我使用 $("#jstree").jstree(true).refresh();尽管 json 使用“selected : true”,但未检查组合框
    • 对不起,我不确定我是否理解
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多