JsTree trigger select_node function

I have jsTree and a button. JsTree function has select_node function

.bind("select_node.jstree", function (event, data) { // some code }) 

Is it possible to fire the select_node event when a button is clicked?

+4
source share
3 answers

A way to use everything that you bind ed in jQuery is using trigger (or triggerHandler ).

 .trigger('select_node.jstree', data) 

See: http://api.jquery.com/trigger/

0
source

You can write

 function onSelectNode(selectedNode) {/* do stuff */} 

and then you can call it in your event binding

 .bind("select_node.jstree", function (event, data) { onSelectNode(data.node); }) 

and then instead of trying to call select_node yourself, you can just call

 onSelect(treeInstance.get_selected(true)[0]) 

Note: you should have already saved the tree link in a variable in the global scope in order to access it later

 treeInstance = $('#div').jstree(true); 
0
source

You can run select_node.jstree with a ie trigger

 .trigger('select_node.jstree', data) 

where the data is completed node what you need to choose

0
source

Source: https://habr.com/ru/post/1392051/


All Articles