jquery - jstree remember opened/closed tree nodes -


i'm using jstree display/manage category tree. i'm fetching tree ajax call , following response returned:

0: {id:35, name:amrs trade, parent_id:null} 1: {id:36, name:trips, parent_id:35} 2: {id:37, name:tribute, parent_id:null} 3: {id:38, name:music, parent_id:null} 4: {id:39, name:recordings, parent_id:38} 5: {id:40, name:live shows, parent_id:38} 6: {id:41, name:others, parent_id:null} 7: {id:42, name:investments, parent_id:null} 8: {id:43, name:gold & silver, parent_id:42} 9: {id:44, name:debentures, parent_id:42} 10: {id:46, name:production, parent_id:35} 11: {id:54, name:real estate, parent_id:42} 

i'm using json_data option render jstree:

$("#incomecategorytree").jstree({     "json_data" : {         "data" : income,         "progressive_render" : true     },     "plugins" : [ "themes", "json_data" ] }) .bind("open_node.jstree close_node.jstree", function (e) {     console.log(e); }); 

i want remember each action user has made (opened or closed tree node), bind both open_node , close_node action. problem have event has no information node clicked:

.event {type: "open_node", timestamp: 1365192438814, jquery183029903660411946476: true, istrigger: true, exclusive: undefined…}  currenttarget: div#incomecategorytree.jstree jstree-0 jstree-default jstree-focused data: null delegatetarget: div#incomecategorytree.jstree jstree-0 jstree-default jstree-focused exclusive: undefined handleobj: object istrigger: true jquery183029903660411946476: true namespace: "jstree" namespace_re: /(^|\.)jstree(\.|$)/ result: undefined target: div#incomecategorytree.jstree jstree-0 jstree-default jstree-focused timestamp: 1365192438814 type: "open_node" __proto__: object 

i guess i'm missing, jstree docs quite poor imho , of options not mentioned...

i've managed following:

$("#incomecategorytree").jstree({     "json_data" : {         "data" : income,         "progressive_render" : true     },     "plugins" : [ "themes", "json_data" ] }) .bind("open_node.jstree close_node.jstree", function (event, data) {     var state = event.type == "open_node" ? "open" : "closed";     incomecategorycontrol.setstate(data.rslt.obj.attr("id"), state) }); 

and object manages tree data

var incomecategorycontrol = {     data: null,     fetchdata: function() {         $.ajax({             type: "get",             datatype: "json",             context: this,             async: false,             url: "../php/client/json.php",             data: {                 type: "incomecategories"             }         }).done(function(response) {             this.data = response;         });     },     getdata: function() {         if (this.data == null) {             this.fetchdata();         }         return this.data;     },     setstate: function(id, value) {         var found = $(this.getdata()).map(function() {             return (this.id == id) ? : null;         });         if (found.length) {             found[0].state = value;             return true;         } else {             return false;         }     } }; 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -