javascript - jsTree复选框事件未触发
问题描述
我无法触发复选框事件,特别enable_checkbox
是disable_checkbox
我初始化 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'
}
}
});
我试过了:
$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');
});
在此期间,一个不那么优雅的黑客;以下对我有用:
$('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);
});
然而,这两种尝试都没有真正触发警报。
API 文档非常模糊,所以想知道是否有人知道我哪里出错了。
解决方案
根据带有 click 事件和 的代码setTimeout
,我想说您要实现的是设置一个事件来检测复选框何时被选中或未选中。
如果是这种情况,您应该分别使用事件check_node.jstree
和uncheck_node.jstree
。
推荐阅读
- java - java中的Jsoup.parse()和Jsoup.ParseBodyFragment()有什么区别?
- redis - Redis Pub/Sub - 发布者也是订阅者?
- javascript - TypeError:WooCommerceRestApi 不是构造函数
- javascript - 在 puppeteer 中将函数传递给 evaluate()
- vue.js - 在 Nuxt 应用程序中为动态路由生成 xml 站点地图
- excel - 根据一个列中的唯一值和另一列中的最大重复值更新列
- python-3.x - 将列表添加到 DF 列
- python - 如何将大图像(800 MB)子集化为较小的图像以创建训练集?
- python-3.x - Sympy——简化并收集不同的变量以进行变量转换
- apache-spark - 以编程方式在 pyspark 中提交 jar