【问题标题】:How to load jstree with closed checked node?如何加载带有封闭检查节点的jstree?
【发布时间】:2015-11-05 10:03:49
【问题描述】:

我设置selected: true

$('#tree3').jstree({ 'core' : {
  'data' : [
    { "id" : "ajson2", "parent" : "#", "text" : "Root node" , state : {opened : false}},
    { "id" : "ajson5", "parent" : "ajson2", "text" : "Child 3" , state : {opened : false, selected: true}, icon: false},
    { "id" : "ajson4", "parent" : "ajson2", "text" : "Child 2" , state : {opened : false, selected: true}, icon: false}
  ]
},
  "checkbox" : {
    "keep_selected_style" : false
  },
  "plugins" : [ "checkbox" ]
});

为什么我的节点被打开了?

如果我尝试selected: false,我会关闭节点,但不会检查。

jsTree - v3.2.1 及更早版本

【问题讨论】:

    标签: javascript jquery tree jstree


    【解决方案1】:

    默认情况下,所有节点都不打开,而是在启动时显示。使用如下所示的 expand_selected_onload,您应该能够在未打开状态下加载树:

    $('#tree3').jstree({ 'core' : {
      'data' : [
        { "id" : "ajson2", "parent" : "#", "text" : "Root node" , state : {opened : false}},
        { "id" : "ajson5", "parent" : "ajson2", "text" : "Child 3" , state : {opened : false, selected: true}, icon: false},
        { "id" : "ajson4", "parent" : "ajson2", "text" : "Child 2" , state : {opened : false, selected: true}, icon: false}
      ],
      expand_selected_onload : false
    },
      "checkbox" : {
        "keep_selected_style" : false
      },
      "plugins" : [ "checkbox" ]
    });
    

    【讨论】:

    • 如果节点没有被检查(或以其他方式使用),它们似乎不会在加载时打开,这很奇怪。不过很好的解决方案!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多