最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - jsTree trigger select_node function - Stack Overflow

matteradmin7PV0评论

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

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

is it possible to trigger select_node event on button click?

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

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

is it possible to trigger select_node event on button click?

Share Improve this question edited Jan 20, 2012 at 13:50 greut 4,3731 gold badge31 silver badges49 bronze badges asked Jan 20, 2012 at 13:46 Iurii DziubanIurii Dziuban 1,0912 gold badges18 silver badges31 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 0

The way to use anything you binded in jQuery is done via trigger (or triggerHandler).

.trigger('select_node.jstree', data)

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

you could write a

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

and then you can call it in your event bind like this

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

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

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

note: you must have already saved the reference of tree in a variable in global scope to access it later

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

You can trigger the select_node.jstree using trigger i.e

.trigger('select_node.jstree', data)

where data is plete node that you need to select

Post a comment

comment list (0)

  1. No comments so far