I am using below logic to get JSON data from JSTree after getting specific data then storing it to localstorage and from there to webserver, I'm not sure whether
i'm doing wrong or right. Please suggest?
$(function() {
$('#container1').jstree({
'core' : {
"animation" : 0,
"check_callback" : true,
"themes" : { "stripes" : true },
'data' : [{"id":"Celulares","text":"Celulares","parent":"#"},
{"id":"AAA","text":"AAA","parent":"Celulares"},
{"id":"Test1","text":"Test1","parent":"#"},
{"id":"BBB","text":"BBB","parent":"Test1"},
{"id":"CCC","text":"CCC","parent":"#"},
]
},
"plugins" : [ "dnd", "contextmenu", "massload", "search", "unique"]
});
$('button').on("click", function () {
window.localStorage.clear();
if (typeof(Storage) !== "undefined") {
var v = $('#container1').jstree(true).get_json('#', {no_state:true,flat:true})
//var mytext = JSON.stringify(v);
//alert(mytext);
var json_obj = $.parseJSON(JSON.stringify(v));
for (var i in json_obj)
{
localStorage.setItem("K"+i, json_obj[i].id+'|'+json_obj[i].text+'|'+json_obj[i].parent);
}
} else {
alert("Sorry! No Web Storage support..");
}
document.getElementById("result").innerHTML = localStorage.getItem("K1");
});
});
Thanks in advance...