使用复选框,当删除所有子节点时,父节点也会在JSTREE中删除



如果使用复选框插件并且所有子节点均已删除,则父节点也将被删除。

$('#jstree').jstree({
"core" : {
    "check_callback" : true,
    "data" : [
        { "text" : "Branch 1", "type" : "branch", "children" : [
            { "text" : "leaf 1.1", "type" : "leaf" },
            { "text" : "leaf 1.2", "type" : "leaf" },
            { "text" : "leaf 1.3", "type" : "leaf" }
           ]
        },
        { "text" : "Branch 2", "type" : "branch", "children" : [
            { "text" : "leaf 2.1", "type" : "leaf" },
            { "text" : "leaf 2.2", "type" : "leaf" },
            { "text" : "leaf 2.3", "type" : "leaf" }
           ]
        }
    ]
},
        "types" : {
            "#" : {
                "valid_children" : ["branch"]
            },
            "branch" : {
                "valid_children" : ["leaf"]
            },
            "leaf" : {
                "valid_children" : []
            }
        },
"plugins" : ["checkbox","types", "dnd", "contextmenu"]});

这是JSFIDDLE演示。了解更多:http://jsfiddle.net/z8l5r9w3/1/

您可以使用JSTREE复选框配置属性'trix_state'和'Cascade',以便在选择所有子节点时未选择父。使用下面的配置,您可以禁用父级选择并确保自动为某个父节点选择选择子节点。

"checkbox" : {
  "three_state": false,
  "cascade": "down"
}

您也可以在此处检查Jstree文档

编辑:删除级联属性可确保在选择节点时选择任何子或父节点。

最新更新