Disable multiple selection in JSTree not working

I am using JSTree in my application with the 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 the following code to select node.

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

However, it selects as node. Thus, it becomes like multiple selection from Javascript.

I ask this question only to confirm that this is the correct JSTree work?

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

But for me, if the multiple selection is set to false, then when choosing a node from javascript, you should also select only one node.

Please correct me if I am wrong.

+8
javascript jquery jstree
source share
3 answers

select_node will select node regardless of the multiple parameter.

The setting restricts user interaction, select_node is a lower level method and will not be limited, therefore you (the developer) can programmatically change the selection without restrictions.

If you want to use the same function that runs when interacting with the user (and therefore is limited to multiple ), use activate_node .

+9
source share

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, }** }); } 
+1
source share
 'checkbox' : { 'deselect_all': true, 'three_state' : false, } 

works great!

0
source share

All Articles