Recrear toda la instancia de jstree con nuevos datos json
Deseo reemplazar todo el contenido de un árbol jstree con nuevos datos json.
Estoy usando jsTree 1.0 descargado el 25 de julio de 2011 desde github
Di que tengo esta función ...
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" ]
});
}
where demo1 se refiere a una
<div id="demo1"></div>
Lo que estoy tratando de hacer es reemplazar completamente el árbol con nuevos datos que cargue desde mi servidor. Para los fines de esta pregunta, sin embargo, imaginemos que solo quiero hacer esto ...
$(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
});
Estoy haciendo esto en base a este enlace, donde Ivan parece defender estohttp: //groups.google.com/group/jstree/browse_thread/thread/b40a1f0ab0f9a66b? fwc = 2
Sin embargo, lo que sucede es que, en la segunda llamada a init, termino obteniendo este error en firebug
instance._get_settings no es una función
ntenté llamar a destruir
$("#demo1").jstree("destroy");
pero eso no solucionó mi problema.
¿Cómo puedo reemplazar todo el árbol con nuevos datos json?