我有这个 JsTree
使用此代码:
var Tree = $("#MyTree");
Tree.jstree({
"core": {
"themes": {
"responsive": false,
"multiple" : false,
},
"data": dataTree
},
"types": {
"default": {
"icon": "icon-lg"
},
"file": {
"icon": "icon-lg"
}
},
"ui": {
"select_limit": 1,
},
"plugins": ["wholerow", "types", "checkbox", "ui", "crrm", "sort"],
"checkbox": {
"three_state": false,
"real_checkboxes": false
}
});
我需要将选择和检查操作分开,用户必须检查他想要的所有节点,但只选择一行时间。 现在,当我点击该行的任何地方时,它会选择该行并选中该节点,只有当用户点击它时我才需要选中该复选框。
我尝试了很多事件,但唯一有效的是:
Tree.on("changed.jstree", function (e, data) { });
捕捉选择和检查的 Action 。
有什么建议吗?
最佳答案
这个答案是关于 jstree 的第 3 版——这是你应该在 2016 年使用的。不幸的是,你的示例代码似乎使用的是 jstree rel 1,我无法帮助你。
对于第 3 版
首先,解开选中状态和选中状态 (checkbox.tie_selection: false) - 参见 the docs
然后,使用check_node.jstree
事件
工作示例
var data1 = [{
"id": "W",
"text": "World",
"state": { "opened": true },
"children": [{"text": "Asia"},
{"text": "Africa"},
{"text": "Europe",
"state": { "opened": false },
"children": [ "France","Germany","UK" ]
}]
}];
$('#Tree').jstree({
core: {
data: data1,
check_callback: false
},
checkbox: {
three_state : false, // to avoid that fact that checking a node also check others
whole_node : false, // to avoid checking the box just clicking the node
tie_selection : false // for checking without selecting and selecting without checking
},
plugins: ['checkbox']
})
.on("check_node.jstree uncheck_node.jstree", function(e, data) {
alert(data.node.id + ' ' + data.node.text +
(data.node.state.checked ? ' CHECKED': ' NOT CHECKED'))
})
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" type="text/css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>
<div id="Tree"></div>
关于javascript - JsTree checkbox - 检查事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35502382/