如何用新的HTML数据重绘我的jstree?

时间:2021-12-05 07:16:17

I have a list of category depending of the publication selected. I want to redraw my category tree depending of the publication selected.

我有一个类别列表,取决于所选的出版物。我想根据所选的出版物重新绘制我的类别树。

I retrieve new html from the server everytime I select a new publication.

每次选择新的出版物时,我都会从服务器中检索新的html。

My HTML look like that :

我的HTML看起来像这样:

<ul>
   <li id="27">
      Moto
      <ul>
         <li id="30">Route</li>
      </ul>
      <ul>
         <li id="31">Cross</li>
      </ul>
   </li>
</ul>
<ul>
   <li id="28">
      Limousine
      <ul>
         <li id="32">3 Portes</li>
      </ul>
      <ul>
         <li id="33">5 Portes</li>
      </ul>
   </li>
</ul>
<ul>
   <li id="36">Avis Mortuaire</li>
</ul>
<ul>
   <li id="49">
      Stellen
      <ul>
         <li id="71">Stellengesuche</li>
      </ul>
      <ul>
         <li id="72">Stellen</li>
      </ul>
      <ul>
         <li id="73">Stellenangebote</li>
      </ul>
   </li>
</ul>
<ul>
   <li id="48">
      Diverses
      <ul>
         <li id="62">Diverses</li>
      </ul>
      <ul>
         <li id="68">Lebenshilfe</li>
      </ul>
      <ul>
         <li id="69">Bekanntschaften</li>
      </ul>
      <ul>
         <li id="70">Direktverkauf/Fabrik-Läden</li>
      </ul>
   </li>
</ul>
<ul>
   <li id="105">Editorial-Anzeige</li>
</ul>

So then I try to do a jq11.jstree.reference('categoryTree').redraw(true) but I get an error Uncaught TypeError: Cannot read property 'className' of undefined.

那么我尝试做一个jq11.jstree.reference('categoryTree')。redraw(true)但是我得到一个错误Uncaught TypeError:无法读取未定义的属性'className'。

So I wonder how can I redraw my jstree with the new html I insert when I change my publication?

所以我想知道如何在更改出版物时用我插入的新html重绘我的jstree?

Thanks

1 个解决方案

#1


Ok finally I have found a way to do this by destroying the old DOM and instance $.jstree.destroy ().

好吧最后我找到了一种方法来破坏旧的DOM和实例$ .jstree.destroy()。

So I just do this way $.jstree.reference('categoryTree').destroy(); then rebuild my DOM $('#categoryTree').html(...); and then I recreate my jstree instance $('#categoryTree').jstree({...})

所以我只是这样做$ .jstree.reference('categoryTree')。destroy();然后重建我的DOM $('#categoryTree')。html(...);然后我重新创建我的jstree实例$('#categoryTree')。jstree({...})

I hope this will help someone else.

我希望这会帮助别人。

#1


Ok finally I have found a way to do this by destroying the old DOM and instance $.jstree.destroy ().

好吧最后我找到了一种方法来破坏旧的DOM和实例$ .jstree.destroy()。

So I just do this way $.jstree.reference('categoryTree').destroy(); then rebuild my DOM $('#categoryTree').html(...); and then I recreate my jstree instance $('#categoryTree').jstree({...})

所以我只是这样做$ .jstree.reference('categoryTree')。destroy();然后重建我的DOM $('#categoryTree')。html(...);然后我重新创建我的jstree实例$('#categoryTree')。jstree({...})

I hope this will help someone else.

我希望这会帮助别人。