重新加载jstree而不刷新页面

时间:2011-07-06 22:30:59

标签: jstree

我正在尝试重新加载jstree而不重新加载或刷新页面,重新加载应该发生onclick一个按钮,所以当点击按钮时我会调用

$("#tree-container").jstree('destroy'); 
//then calling the function that reads or renders the tree

在没有树已经渲染的情况下工作正常,但是当树已经渲染并且我点击按钮时我得到了这个:“无法调用未定义的方法init。”错误发生在jstree plugin

我甚至尝试删除容器,然后在调用读取树的函数之前将其重新附加到它的父容器

$("#tree-container").remove();

$('#parent-tree-container').append($('<div id="tree-container"></div>'));
//then called the function that reads/renders the tree  

但仍然没有奏效。 :(

提前致谢。

2 个答案:

答案 0 :(得分:4)

这将进行ajax调用以刷新树,但不会包含它所包含的页面:

$.jstree._reference($("#tree-container")).refresh(-1);

这是最好的方法,但如果你愿意,你可以在初始div上重建jstree而不首先破坏它:

$("#tree-container").jstree({

答案 1 :(得分:0)

您使用的是jQuery 1.6.2吗?如果是这样,尝试更低版本 - 1.6.1应该工作。 - see here

相关问题