首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JSTREE -刷新jstree,以便重新运行‘bind(“loaded.jstree”)中的所有代码

JSTREE -刷新jstree,以便重新运行‘bind(“loaded.jstree”)中的所有代码
EN

Stack Overflow用户
提问于 2011-12-20 11:47:20
回答 2查看 8.5K关注 0票数 5

在我的页面上,我有一个按钮,点击后,刷新页面上的jstree。

代码语言:javascript
复制
<input type="button" value="Test" onclick='$j("#demo2").jstree("refresh");'/>

现在,当jstree加载时,从2D数组读取数据,并根据在该数组中找到的数据更改节点图标。我需要一个函数,它将刷新或重新加载jstree,同时根据从2D数组读取的数据显示适当的节点图标。

如果我使用'$j("#demo2").jstree("refresh");',树将被重新加载,但它不会保留以前的打开状态。

jstree代码

代码语言:javascript
复制
$j("#demo2").jstree({
          "ui" : {
            "select_limit" : -1,
            "select_multiple_modifier" : "ctrl",
            "select_range_modifier" :"shift",
          },

          "json_data" : {
            "progressive_render" : false,
            "selected_parent_open": true,
            "ajax" : {
              "url" : "/json/test1.json"
            }
          },

          "plugins" : [ "themes", "json_data", "ui", "crrm", "contextmenu" ],

          'contextmenu' : {
          'items' : customMenu
          }

      })//end of jstree function


      /***************************************************************************
      When the jstree is first loaded, loop through the data retrieved
      from the database (stored previously in a 2d array called 'status_from_db') and
      select all jstree nodes found in that array.
      ***************************************************************************/
     $j("#demo2").bind("loaded.jstree", function (e, data) {    
      var inst = data.inst;
      var i;
      for (i = 0; i < status_from_db.length; ++i) {
          var node_name = status_from_db[i][0];
          $j("#demo2").find($j("li[name='"+node_name+"']")).each(function (k, v) {
            inst.select_node(v);

      /***************************************************************************
      Based on the retrieved data, assign the correct class to the variable 
      'selected_class and then modify the class of the <li> tag of the respective 
      node.
      ***************************************************************************/
            var node_strength = status_from_db[i][1];
            var node_add_strength = status_from_db[i][2];
            var selected_class;
            if (node_strength == "present" && node_add_strength == ""){
              selected_class = "jstree-icon4";
            }
            else if (node_strength == "present" && node_add_strength == "strong")  {
              selected_class = "jstree-icon3";
            }


            $j("li[name='"+node_name+"'] > ins").attr("class",selected_class);// set class to display new icon
            $j("li[name='"+node_name+"'] > a ins").attr("class",selected_class);// set class to display new icon    
          });
      }

   });

});

是否有一种重新加载/刷新树的方法,以便重新运行'$j("#demo2").bind("loaded.jstree", function (e, data) {'函数中的所有代码?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-12-20 11:59:56

你可以自己触发这个事件

代码语言:javascript
复制
$j("#demo2").trigger("loaded.jstree");
票数 6
EN

Stack Overflow用户

发布于 2013-11-21 21:48:10

有一个事件在刷新链接到数据重新加载的树或节点时触发。它是

代码语言:javascript
复制
.bind("reopen.jstree", function(e,data) {
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8574918

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档