2014-12-23 16 views
10

Aşağıdaki verilerle bir ağaç oluşturdum. Bu işlemden sonra menüler arasında sürükle bırak işlemi yaptım. Sonuç olarak menü yapmam değişti. İlk verilerimle aynı yapıya sahip yeni json verilerini vermek istiyorum. Ağaçtan nasıl veri alabilirim? Plese bana yardım etsin.jstree ağaçtan yeni json verileri al

Bu kodu denedim, ancak bu ihracat çok karmaşık json. İlk veri formatımı istiyorum. Menünün

  var v = $('#data').jstree(true).get_json(); 
      var mytext = JSON.stringify(v); 
      alert(mytext); 

ilk durum: menünün

enter image description here

son durum:

enter image description here

// 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 

cevap

29

Ağaçtan json almak için en basit yol buldu;

var v = $('#data').jstree(true).get_json('#', {flat:true}) 
var mytext = JSON.stringify(v); 
alert(mytext);