Javascript JSTree从选择中排除不同的节点

Javascript JSTree从选择中排除不同的节点,javascript,jstree,Javascript,Jstree,在我的项目中,我有3个公司根节点和测试子节点。带有复选框 - []Company1 -- []Test1 -- []Test2 - []Company2 -- []Test1 -- []Test2 -- []Test 3 - []Company3 -- []Test1 树要复杂得多,但对于问题,我降低了级别。然而,我想管理的是,禁止选择两家公司。作为示例,如果选择了来自Company2的Test1,并且用户选择了来自Company1的Test1,那么来自Company1和Company3的所

在我的项目中,我有3个公司根节点和测试子节点。带有复选框

- []Company1
-- []Test1
-- []Test2
- []Company2
-- []Test1
-- []Test2
-- []Test 3
- []Company3
-- []Test1

树要复杂得多,但对于问题,我降低了级别。然而,我想管理的是,禁止选择两家公司。作为示例,如果选择了来自Company2的Test1,并且用户选择了来自Company1的Test1,那么来自Company1和Company3的所有选择都将被取消选中

我的jstree代码是:

$(function () {
    $('#html1').on('select_node.jstree', function(e, data){
            var countSelected = data.selected.length;
            if (countSelected>1) {
                data.instance.deselect_node( [ data.selected[0] ] );
            }
        });
    $.ajax({
        type: "get",
        url: "/jstreecontent",
        dataType: "json",
        success: function(data) {
            $('#html1').jstree({
                'core' : {
                    'data' : data
                },
                "checkbox" : {
                    "keep_selected_style" : false
                },
                "plugins" : [ "checkbox", "contextmenu"],
                "checkbox": {
                    three_state : true, // 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
                },
                "contextmenu": {
                    "items": function ($node) {
                        var tree = $("#html1").jstree(true);
                        if($node.a_attr.type === 'test')
                            return getTestContextMenu($node, tree);
                    }
                }
            });
        },
        complete: function() {
            // This function will be triggered always, when ajax request is completed, even it fails/returns other status code
            console.log("complete");
        },
        error: function() {
            // This will be triggered when ajax request fail.
            console.log("Error");
        }
    });

});
如果我移除该部件:

                "checkbox": {
                    three_state : true, // 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
                },
根节点的选择工作得很完美,只允许一个根节点,但我不能选择整个根,只选择它的节点。所以我认为

    $('#html1').on('select_node.jstree', function(e, data){
            var countSelected = data.selected.length;
            if (countSelected>1) {
                data.instance.deselect_node( [ data.selected[0] ] );
            }
        });
正在所有节点上工作,而不仅仅是在顶部节点上。也许这是错误的


但似乎,我失败了,这是错误的方式。我希望其他人过去也有同样的问题,并给我一个提示。

“我失败了”:您提供的代码没有任何用处。我想您在该处理程序中有一些代码。你能添加它吗?用单选按钮让公司选择“可”。条件有点混乱。请提供更多信息,说明您希望何时取消选中公司1、2或3上的复选框。如果您可以提供代码片段,将更容易理解问题。问题已更新为更多信息和代码。