How to associate a data to a node in jstree?

Abhii picture Abhii · Apr 5, 2012 · Viewed 34.9k times · Source
$("#ifTree").jstree({
            "plugins" : ["themes","html_data","ui","crrm"], 
            "themes" : {
                    "theme" : "apple",
                    "dots" : true,
                    "icons" : false
            }           
    });

    $("#createIf_c").click(function () { 
        $("#ifTree").jstree("create",null,"inside",  { "data" :{ title:"if",value:"expression"} },
                function() {}, true);
    });
$("#display").click(function(){
            var a = $.jstree._focused().get_selected();
            alert(a.attr("value"));
    });

In this above code I have created a jstree and upon click of a button with id #createIf_c I am adding a node with title "if" but as I want some more data to be associated with this node , I have added more attributes to it while creating the node. Next when I am trying to access this associated data, here "value" then I am getting the alert 'undefined'. So is there a different way for associating data with a node? or a different way of accessing the associated data of a node is jstree?..please help....

Answer

mohammed barqawi picture mohammed barqawi · Apr 29, 2014

you can put your extra data in the JSON node.data this is not documented
enter image description here