2011-12-20 21 views
5

Trên trang của tôi, tôi có một nút, được nhấp vào, làm mới một jstree được tìm thấy trên trang đó.JSTREE - làm mới jstree sao cho tất cả mã trong 'bind ("loaded.jstree")' được chạy lại

<input type="button" value="Test" onclick='$j("#demo2").jstree("refresh");'/> 

Bây giờ, khi tải jstree, dữ liệu được đọc từ mảng 2D và biểu tượng nút được thay đổi theo dữ liệu tìm thấy trong mảng đó. Tôi cần một chức năng sẽ làm mới hoặc tải lại jstree và đồng thời hiển thị các biểu tượng thích hợp cho các nút dựa trên dữ liệu được đọc từ mảng 2D.

Nếu tôi sử dụng '$j("#demo2").jstree("refresh");', cây được tải lại nhưng không giữ lại trạng thái mở trước đó của nó.

đang jstree

$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  
      }); 
     } 

    }); 

}); 

Có một cách để tải lại/làm mới cây như vậy mà tất cả các mã trong '$j("#demo2").bind("loaded.jstree", function (e, data) {' chức năng được chạy lại?

Trả lời

6

bạn có thể kích hoạt sự kiện mình

$j("#demo2").trigger("loaded.jstree"); 
0

Có một sự kiện kích hoạt khi bạn làm mới cây hoặc nút đó được liên kết với tải lại dữ liệu. nó là

.bind("reopen.jstree", function(e,data) { 
Các vấn đề liên quan