JsTree复选框 - 检查事件 [英] JsTree checkbox - check event
问题描述
我有这个JsTree
I have this JsTree
< img src =https://i.stack.imgur.com/2Nm3d.pngalt =在此处输入图片说明>
代码:
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
}
});
我需要分离选择和检查操作,用户必须检查他想要的所有节点但是选择只有一排时间。
现在,当我点击该行的任何地方时,它选择该行并检查该节点,我只需要在用户点击它时选中该复选框。
I need to separate the selection and the check action, the user must check all node he wants but select only one row for time. for now when I click everywhere on the row it select that row and check that node, i need to check the checkbox only if the user click on it.
我尝试了很多活动,但唯一的工作是:
I try so much event but the only that work is:
Tree.on("changed.jstree", function (e, data) { });
同时捕捉选择和检查的行为。
that catch both the action of selection and check.
有什么建议吗?
推荐答案
这个答案是关于jstree的第3版 - 这是你应该在年使用的2016.不幸的是你的示例代码,似乎使用jstree rel 1,我无法帮助你。
This answer is about the release 3 of jstree - that is what you should use in year 2016. Unfortunaltely your sample code, seems using jstree rel 1, and I can't help you about that.
对于第3版
首先,解开所选状态和复选状态(checkbox.tie_selection:false) - 参见文档
First of all, untie the selected and the checked states (checkbox.tie_selection: false) - see 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>
这篇关于JsTree复选框 - 检查事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!