2015-08-18 33 views
1

我正在嘗試開發一種自定義搜索方法,只在父項目之間進行搜索,並顯示樹結構的子項目。然而,根據我所做的測試,我發現這種方法沒有被觸發,並且仍然使用默認搜索方法。我期待着您的幫助。jstree自定義搜索方法不起作用

謝謝。

$(function() { 
      $.expr[':'].jstree_parent_search = function(a, i, m) { 
       console.log(a); 
      }; 

      $(".jstree").jstree({ 
       'core': { 
        'data': GetAllPages(), 
        'check_callback': true, 
        'themes': { 
         "icons": false 
        } 
       }, 
       'search': { 
        'search_method': 'jstree_parent_search' 
       }, 
       'plugins': ['checkbox', 'search'] 
      }); 

      var po = false; 
      $('#txtSearch').keyup(function() { 
       if (po) { clearTimeout(po); } 
       po = setTimeout(function() { 
        var v = $('#txtSearch').val(); 
        $('.jstree').jstree(true).search(v); 
       }, 250); 
      }); 
     }); 

回答

0

沒有search_method選項 - 請閱讀API文檔。您可以使用search_callback - 它是一個函數,將在實例的作用域中爲每個可能的節點調用 - 它全部在API文檔中:
https://www.jstree.com/api/