禁用JSTree中的多个选择不起作用

Nir*_*ani 10 javascript jquery jstree

我在我的应用程序中使用JSTree,代码如下.

this.CreateTreeView = function () {
    $('#jstree_demo_div').jstree({
        'core': {
            'multiple': false,
            'data': [
               { "id": "ajson1", "parent": "#", "text": "Simple root node" },
               { "id": "ajson2", "parent": "#", "text": "Root node 2" },
               { "id": "ajson3", "parent": "ajson2", "text": "Child 1" },
               { "id": "ajson4", "parent": "ajson2", "text": "Child 2" },
            ]
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

如我的代码所示,我试图禁用多个选择.

现在当我使用以下代码选择节点时.

$("#jstree_demo_div").jstree().select_node("ajson3");
$("#jstree_demo_div").jstree().select_node("ajson4");
Run Code Online (Sandbox Code Playgroud)

它仍然选择两个节点.所以它变得像Javascript中的多个选择.

我提出这个问题只是为了确认JSTree的工作是否正确?

我知道我可以在使用deselect_all函数选择任何节点之前取消选择所有节点.

但据我说,如果多个选择设置为false,那么从javascript中选择节点也应该只选择一个节点.

如果我错了,请纠正我.

vak*_*ata 10

select_node无论multiple设置如何,都将选择一个节点.

该设置仅限制用户交互,select_node是一种较低级别的方法,不受限制,因此您(开发人员)可以无限制地以编程方式修改选择.

如果要使用由用户交互(因此受限制multiple)触发的相同功能,请使用activate_node.

  • 您好vakata,感谢您的支持.你的图书馆JSTree真的很棒. (4认同)

اسم*_*ارع 5

只需使用这个配置

this.CreateTreeView = function () {

    **"plugins" : [
                "checkbox",  
            ],**  

    $('#jstree_demo_div').jstree({
        'core': {
            **'multiple': false,**
            'data': [
               { "id": "ajson1", "parent": "#", "text": "Simple root node" },
               { "id": "ajson2", "parent": "#", "text": "Root node 2" },
               { "id": "ajson3", "parent": "ajson2", "text": "Child 1" },
               { "id": "ajson4", "parent": "ajson2", "text": "Child 2" },
            ]
        },

        **'checkbox' : {            
            'deselect_all': true,
             'three_state' : false, 
        }**

    }); }
Run Code Online (Sandbox Code Playgroud)