How to access jsTree node attributes after checkbox has been checked?

I would like to know how to access the jsTree node attributes after the node checkbox has been checked.

I am using $("#jstree").bind('check_node.jstree', function(e, data) {

to run my code after clicking a checkmark.

Now I want to access the attributes of node. But I don't know how to use an object data

to get the attributes. So let's say in my jsfiddle I want to display the value of an attribute along with the text "clicked and checked"

Could you explain how and why? I lost my reference to jsTree / jQuery objects.

jsfiddle working example

==== Update

The jsTree data definition can have node attributes defined. I want to programmatically validate attributes and then run different attributes of the code. In my case "log" .

data = [
    {
        "data": "Basics",
        "attr":{"log":"shared"},
    },
    {
        "data": "All",
        "attr":{"log":"bdrs"},
    }
]

      

+3


source to share


1 answer


you can simply do:

$("#jstree").bind('check_node.jstree', function(e, data) {
    $("#list").append('<BR>clicked and ' + node_is_check(data));
    var node = data.rslt.obj;
    console.log( node.attr("log") ); //shows bdrs when All is checked
});

      



Updated script: jsFiddle Demo

Did you mean something like this

+4


source







All Articles