Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind with jstree on expand and on collapse events

I am facing difficulty to bind jstree with an on-expand/on-collapse event. I am currently binding the jstree with selected_node event like this :

$(function () {
$("#tree").jstree({ 
"json_data" : {
    "data" : [
        { 
            data : "/", 
            attr : { "id" : "root"},
            state : "closed",
            "children" : [ { "data" : "child1",
                            "attr" : { "id" : "child1.id" },
                            "children" : [ ] }
                         ]
        },
    ]
},
"plugins" : [ "themes", "json_data", "crrm", "ui" ]
})
.bind("select_node.jstree",function(event, data) { . . . }

I am now looking for the same event handling functionality within {...} for on-expand/on-collapse event as well. Need help to figure out how can that be done.

like image 789
RAhul Avatar asked Nov 30 '25 14:11

RAhul


2 Answers

.on('open_node.jstree', ....);

and

.on('close_node.jstree', ....);
like image 131
stevemarvell Avatar answered Dec 03 '25 04:12

stevemarvell


If you want more information about node (like id):

$("#jstree").on("open_node.jstree", function (e, data) { alert("Open node_id: " + data.node.id); });
$("#jstree").on("close_node.jstree", function (e, data) { alert("Close node_id: " + data.node.id); });
like image 28
Dani Avatar answered Dec 03 '25 05:12

Dani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!