Vorrei sostituire l'intero contenuto di un albero jstree con nuovi dati JSON.Ricreare intera istanza jstree con i nuovi dati JSON
sto usando jsTree 1.0 scaricato 25 Luglio 2011 da github
Dire che ho questa funzione ...
function init_my_tree(my_json_data)
{
$("#demo1").jstree({
themes: {
"theme": "classic",
"dots": false,
"icons": true,
"url": "//js.myliburl.com/jstree/themes/classic/style.css"
},
json : {
data : my_json_data
},
plugins : [ "core","ui","themes", "json" ]
});
}
dove demo1 si riferisce ad un
<div id="demo1"></div>
Quello che ho sto cercando di sostituire completamente l'albero con i nuovi dati che carico dal mio server. Ai fini di questa domanda, però, facciamo finta Voglio solo fare questo ...
$(document).ready(function() {
var text_data = '[{"title":"All","data":{"jstree":{"opened":true}},"children":[{"title":"Item 1","data":{"jstree":{}},"children":false,"li_attr":{"id":"1","class":"jstree-leaf","href":"#"},"a_attr":{"href":"#"}},{"title":"Item B","data":{"jstree":{}},"children":false,"li_attr":{"id":"2","class":"jstree-last","href":"#"},"a_attr":{"href":"#"}}],"li_attr":{"id":"0","class":"jstree-last","href":"#"},"a_attr":{"href":"#"}}]';
var my_json_data = $.parseJSON(text_data);
init_my_tree(my_json_data); // initialize the tree view
text_data = '[{"title":"Something Else","data":{"jstree":{"opened":true}},"children":[{"title":"Item A","data":{"jstree":{}},"children":false,"li_attr":{"id":"1","class":"jstree-leaf","href":"#"},"a_attr":{"href":"#"}},{"title":"Item 2","data":{"jstree":{}},"children":false,"li_attr":{"id":"2","class":"jstree-last","href":"#"},"a_attr":{"href":"#"}}],"li_attr":{"id":"0","class":"jstree-last","href":"#"},"a_attr":{"href":"#"}}]';
my_json_data = $.parseJSON(text_data);
init_my_tree(my_json_data); // re-initialize the tree view to load with new data
});
sto facendo questo in base a questo link, dove Ivan sembra sostenere questa http://groups.google.com/group/jstree/browse_thread/thread/b40a1f0ab0f9a66b?fwc=2
Tuttavia, quello che sta succedendo è che, al 2 ° chiamata a init, finisco per geting questo errore in firebug
instance._get_settings non è una funzione
Ho provato a chiamare distruggere
$("#demo1").jstree("destroy");
ma che non ha risolvere il mio problema.
Come posso sostituire l'intero albero con i nuovi dati JSON?
Se si usa qualcosa come plug-in "dnd", allora la soluzione non ha funzionato più. –
@SamanGholami Quindi cosa dovremmo fare in questo caso? – DonkeyKong