I created a tree with the following data. After this process, I made a drag-drop process between menus. And as a result, my menu structure was changed. I want to export new JSON data which has the same structure as my first data. How can I get data from the tree? Please help me.
I tried this code, but this export very complicated JSON. I won't like my first data format.
var v = $('#data').jstree(true).get_json();
var mytext = JSON.stringify(v);
alert(mytext);
First state of menu:
Last state of menu:
// html demo
$('#html').jstree();
// inline data demo
$(function() {
var arrayCollection = [
{"id": "animal", "parent": "#", "text": "Animals"},
{"id": "device", "parent": "#", "text": "Devices"},
{"id": "dog", "parent": "animal", "text": "Dogs"},
{"id": "lion", "parent": "animal", "text": "Lions"},
{"id": "mobile", "parent": "device", "text": "Mobile Phones"},
{"id": "lappy", "parent": "device", "text": "Laptops"},
{"id": "daburman", "parent": "dog", "text": "Dabur Man", "icon": "/"},
{"id": "Dalmation", "parent": "dog", "text": "Dalmatian", "icon": "/"},
{"id": "african", "parent": "lion", "text": "African Lion", "icon": "/"},
{"id": "indian", "parent": "lion", "text": "Indian Lion", "icon": "/"},
{"id": "apple", "parent": "mobile", "text": "Apple IPhone 6", "icon": "/"},
{"id": "samsung", "parent": "mobile", "text": "Samsung Note II", "icon": "/"},
{"id": "lenevo", "parent": "lappy", "text": "Lenevo", "icon": "/"},
{"id": "hp", "parent": "lappy", "text": "HP", "icon": "/"}
];
$('#data').jstree({
'core' : {
'check_callback' : true,
'data' :arrayCollection ,
},
"plugins" : ["dnd","wholerow"]
});
});//function
I found the most simple way to get json from tree;
var v = $('#data').jstree(true).get_json('#', {flat:true})
var mytext = JSON.stringify(v);
alert(mytext);