使用复选框,当所有子节点都被删除时,父节点也会在 JStree 中被删除
Using Checkbox, When all child nodes are deleted, parent node also getting deleted in JStree
如果使用 CheckBox Plugin 并删除了所有子节点,则父节点也会被删除。
$('#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 复选框配置属性 'three_state' 和 'cascade',以便在选择所有子节点时不选择父节点。使用下面的配置,您可以禁用父节点选择,并确保为某个父节点选择自动选择子节点。
"checkbox" : {
"three_state": false,
"cascade": "down"
}
您还可以查看 jsTree 文档 here
编辑:删除级联 属性 确保在选择节点时不会选择子节点或父节点。
如果使用 CheckBox Plugin 并删除了所有子节点,则父节点也会被删除。
$('#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 复选框配置属性 'three_state' 和 'cascade',以便在选择所有子节点时不选择父节点。使用下面的配置,您可以禁用父节点选择,并确保为某个父节点选择自动选择子节点。
"checkbox" : {
"three_state": false,
"cascade": "down"
}
您还可以查看 jsTree 文档 here
编辑:删除级联 属性 确保在选择节点时不会选择子节点或父节点。