最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Disable Multiple Selection in JSTree is not working - Stack Overflow

programmeradmin0浏览0评论

I am using JSTree in my application with following code.

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" },
            ]
        }
    });
}

As shown in my code i am trying to disable multiple selection.

Now when i use following code to select node.

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

Still it select both node. So it becomes like multiple selection from Javascript.

I am putting this question just to confirm that is it correct working of JSTree?

I know that i can deselect all node before selecting any node using deselect_all function.

But according to me if multiple selection is set to false then selecting node from javascript also should select only one node.

Please correct me if i am wrong.

I am using JSTree in my application with following code.

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" },
            ]
        }
    });
}

As shown in my code i am trying to disable multiple selection.

Now when i use following code to select node.

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

Still it select both node. So it becomes like multiple selection from Javascript.

I am putting this question just to confirm that is it correct working of JSTree?

I know that i can deselect all node before selecting any node using deselect_all function.

But according to me if multiple selection is set to false then selecting node from javascript also should select only one node.

Please correct me if i am wrong.

Share Improve this question edited Sep 3, 2015 at 15:39 Nirav Kamani asked Sep 3, 2015 at 11:59 Nirav KamaniNirav Kamani 3,2727 gold badges40 silver badges69 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 16

select_node will select a node regardless of the multiple setting.

The setting only limits user interaction, select_node is a lower level method and will not be limited, so you (the developer) can modify the selection programmatically without limitation.

If you want to use the same function that is triggered by user interaction (and is therefore limited by multiple) use activate_node.

just use this configuration

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

works fine!

To Disable checkbox multi-select in JStree this code also work perfectly :

   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);
                    }
                })
发布评论

评论列表(0)

  1. 暂无评论