简体   繁体   中英

JsTree checkbox - check event

I have this JsTree

在此输入图像描述

with this code:

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.

Any suggestions?

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.

For release 3

First of all, untie the selected and the checked states (checkbox.tie_selection: false) - see the docs

Then, use the check_node.jstree event

Working example

 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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM