? Спасибо
у заменить все содержимое дерева Jstree новыми данными JSON.
Я использую jsTree 1.0, загруженную 25 июля 2011 года с github.
Скажи, у меня есть эта функция ...
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" ]
});
}
где demo1 относится к
<div id="demo1"></div>
Я пытаюсь полностью заменить дерево новыми данными, которые я загружаю с моего сервера. Для целей этого вопроса, однако, давайте представим, что я просто хочу сделать это ...
$(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
});
Я делаю это на основе этой ссылки, где Иван, кажется, защищает этоhttp://groups.google.com/group/jstree/browse_thread/thread/b40a1f0ab0f9a66b?fwc=2
Тем не менее, происходит то, что при втором вызове init я получаю эту ошибку в firebug
instance._get_settings не является функцией
Я пытался призвать уничтожить
$("#demo1").jstree("destroy");
но это не решило мою проблему.
Как я могу заменить все дерево новыми данными JSON?