如果使用CheckBox插件且所有子节点均被删除,则父节点也将被删除。
$('#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/
答案 0 :(得分:1)
您可以使用jsTree复选框配置属性'three_state'和'cascade',以便在选择所有子节点时不选择父级。使用以下配置,您可以禁用父节点选择,并确保为某个父节点选择自动选择了子节点。
"checkbox" : {
"three_state": false,
"cascade": "down"
}
您还可以查看jsTree文档here
编辑:删除级联属性可确保在选择节点时不会选择任何子节点或父节点。