使用jstree做树形控件,很方便,但是现在又一个需求,就希望在点击父节点的时候,不和子阶段关联,不让子节点关联选中。
jstree给我们提供了配置项three_state,只要我们在初始化jstree控件的时候,加一下这个配置项并设置树形为false就可以。
$("#tree").jstree({
"checkbox": {
"keep_selected_style": false,
// 选中父节点,不和子节点关联同时选中
"three_state": false
},
"plugins": ["checkbox", "changed"],
'core': {
'data': [
{
"id": 1,
"state": {
"opened": true
},
"text": "Root node1",
"children": [
{
"id": 2,
"text": "Child node 1"
},
{
"id": 3,
"text": "Child node 2",
"state": {
"opened": false,
"disabled": false,
"selected": false
}
},
{
"id": 4,
"state": {
"opened": true,
"disabled": false
},
"text": "Child node3",
"children": [
{
"id": 99,
"text": "Child node3-1",
state: {
opened: true, // is the node open
disabled: false, // is the node disabled
selected: false // is the node selected
},
},
{
"id": 106,
"text": "Child node3-2"
}
]
}
]
}
]
}
});