[英]jsTree checkbox events not firing
I'm having trouble getting checkbox events to fire, specifically enable_checkbox
and disable_checkbox
我无法触发复选框事件,特别是
enable_checkbox
和disable_checkbox
My code to init jsTree is: 我初始化jsTree的代码是:
$('#contenteditor-hierarchy').jstree({
"plugins": [
"checkbox"
],
"checkbox": {
"visible": true,
"tie_selection": false,
"whole_node": false
},
"core": {
"check_callback": true,
"data": {
"url": function (node) {
//...
},
"type": "get",
"data": function (node) {},
"dataType": 'json'
}
}
});
and I have tried: 我已经尝试过:
$tree.bind('enable_checkbox.jstree', function() {
alert('test');
});
// and...
$('#contenteditor-hierarchy').on('enable_checkbox.jstree', function() {
alert('test');
});
// as well as..
$(document).on('enable_checkbox.jstree', function() {
alert('test');
});
for the interim, a not so classy hack; 在此期间,这不是一个很经典的技巧; the below works for me:
以下对我有用:
$('body').on('click', '.jstree-checkbox', function(e) {
// at the time of this event firing, jstree hadn't finished handling the click event
// so I had to timeout....
setTimeout(function() {
console.log($tree.jstree(true).get_checked());
}, 200);
});
However in neither attempt was an alert actually fired. 但是,实际上都没有发出警报。
The API docs is quite vague so wondering if anyone is aware of where I am going wrong. API文档非常模糊,因此想知道是否有人知道我要去哪里。
Based on the code with the click event and the setTimeout
, I would say that what you are trying to achieve is to set an event to detect when the checkbox is checked or unchecked. 基于带有click事件和
setTimeout
的代码,我想说的是您要实现的是设置一个事件以检测复选框处于选中状态还是未选中状态。
If that is the case, you should use the events check_node.jstree
and uncheck_node.jstree
respectively. 在这种情况下,应分别使用事件
check_node.jstree
和uncheck_node.jstree
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.