【问题标题】:Reloading a jstree without refreshing the page在不刷新页面的情况下重新加载 jstree
【发布时间】:2011-07-06 22:30:58
【问题描述】:

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

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

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

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

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

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

但这仍然不起作用。 :(

提前致谢。

【问题讨论】:

    标签: jstree


    【解决方案1】:

    这将调用 ajax 来刷新树,但不会刷新它所在的页面:

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

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

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

    【讨论】:

    • 我需要重建树,因为它的内容发生了变化。我用来构建树的函数具有您指出的构建部分。即 $("#tree-container").jstree({ 等我仍然得到这个:“无法调用未定义的方法 init。”如果树的实例已经呈现。
    • 即使内容发生变化,您也可以使用刷新,这就是它的用途。如果需要,请在 jstree url 中指定一个标志。另外,编辑您的答案以添加您的树声明,而不仅仅是销毁部分
    • 也可能:$('#tree-container').jstree('refresh'); 这更像是“jquery-way”。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-20
      • 2017-08-13
      • 2013-10-09
      • 2011-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多