【问题标题】:jsTree checkbox events not firingjsTree复选框事件未触发
【发布时间】:2019-06-16 10:50:39
【问题描述】:

我无法触发复选框事件,特别是 enable_checkboxdisable_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');
});

在此期间,一个不那么优雅的 hack;以下对我有用:

$('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 文档非常模糊,所以想知道是否有人知道我哪里出错了。

【问题讨论】:

    标签: javascript jstree


    【解决方案1】:

    根据带有点击事件和setTimeout 的代码,我想说你想要实现的是设置一个事件来检测复选框何时被选中或取消选中。

    如果是这种情况,您应该分别使用事件check_node.jstreeuncheck_node.jstree

    【讨论】:

    • 你是对的!答案就在我不得不相信的术语中!!....而且我忽略了两个选项,请注意。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-09
    • 2011-11-17
    • 2016-04-13
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多