jstree设置默认只展开根节点的第一级子节点,其他二级节点不展开,且默认选中一级节点方法

jstree设置默认只展开根节点的第一级子节点,其他二级节点不展开,且默认选中一级节点方法:

注意,以下绑定的方法已经不适用最新jstree了:

$(function () {
$("#demo")
.bind("loaded.jstree", function (e, data) {
      data.inst.open_all(-1); // -1 opens all nodes in the container
})
.jstree({
  //  自定义设置
})

最新实现方法:将根节点的state状态设置为相应状态即可实现 默认展开,默认选中等。

具体代码如下:【IP21.cn】

$('#jstree2').jstree({'plugins':["wholerow","checkbox"], 'core' : {
    'data' : [
        {
            "text" : "Same but with checkboxes",
            "children" : [
                { "text" : "initially selected", "state" : { "selected" : true } },
                { "text" : "custom icon URL", "icon" : "//jstree.com/tree-icon.png" },
                { "text" : "initially open", "state" : { "opened" : true }, "children" : [ "Another node" ] },
                { "text" : "custom icon class", "icon" : "glyphicon glyphicon-leaf" }
            ]
        },
        "And wholerow selection"
    ]
}});

原文出自【IP21.cn】,转载请留下本文永久链接: http://ip21.cn

抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址