JsTree复选框 - 检查事件

Lor*_*ssi 9 javascript jquery jstree

我有这个JsTree

在此输入图像描述

使用此代码:

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
            }
        });
Run Code Online (Sandbox Code Playgroud)

我需要分离选择和检查操作,用户必须检查他想要的所有节点,但只选择一行时间.现在,当我点击行的每个地方时,它选择该行并检查该节点,我只需要在用户点击它时选中该复选框.

我尝试了很多活动,但唯一的工作是:

Tree.on("changed.jstree", function (e, data) { });
Run Code Online (Sandbox Code Playgroud)

同时捕捉选择和检查的动作.

有什么建议?

edc*_*c65 22

这个答案是关于jstree的第3版 - 这是你应该在2016年使用的.不幸的是你的示例代码,似乎使用jstree rel 1,我无法帮助你.

发布3

首先,解开选中状态和复选状态(checkbox.tie_selection:false) - 查看文档

然后,使用该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'))
})
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)