繁体   English   中英

在 JSTree 中禁用多选不起作用

[英]Disable Multiple Selection in JSTree is not working

我使用以下代码在我的应用程序中使用 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" },
            ]
        }
    });
}

如我的代码所示,我试图禁用多项选择。

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

$("#jstree_demo_div").jstree().select_node("ajson3");
$("#jstree_demo_div").jstree().select_node("ajson4");

它仍然选择两个节点。 所以它变得像是从 Javascript 中进行多项选择。

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

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

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

如果我错了,请纠正我。

select_node将选择一个节点而不管multiple设置。

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

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

只需使用此配置

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, 
        }**

    }); }
'checkbox' : {            
 'deselect_all': true,
 'three_state' : false, 
}

工作正常!

要在 JStree 中禁用复选框多选,此代码也可以完美运行:

   var tmp=null;   /// to prevent recursion
              treeobj.on("check_node.jstree uncheck_node.jstree", function(e, data)                 {
                    if(tmp!=data.node.id){      
                        tmp=data.node.id;
                        treeobj.jstree("uncheck_all", null);
                        treeobj.jstree("check_node",data.node.id);
                    }
                })

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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