2012-01-06 97 views

回答

0

它看起來並不像您可以使用標準jsTree search plugin

好消息,你可以write your own search function做到這一點。這是一段摘錄。它顯示了演示如何使用自定義功能來搜索用空格分隔的多個單詞:

我需要尋找用空格隔開,所以我給 多話,你我的功能添加到搜索插件(目前搜索引擎 插件只搜索一個字)。

/* 
* jsTree search plugin 
* Enables both sync and async search on the tree 
* DOES NOT WORK WITH JSON PROGRESSIVE RENDER 
*/ 
(function ($) { 

    $.expr[':'].jstree_contains_multi = function(a,i,m){ 

     var word, words = []; 
     var searchFor = m[3].toLowerCase().replace(/^\s+/g,'').replace(/\s+$/g,''); 
     if(searchFor.indexOf(' ') >= 0) { 
      words = searchFor.split(' '); 
     } 
     else { 
      words = [searchFor]; 
     } 
     for (var i=0; i < words.length; i++) { 
      word = words[i]; 
      if((a.textContent || a.innerText || "").toLowerCase().indexOf(word) >= 0) { 
       return true; 
      } 
     } 
     return false; 

    }; 

    $.expr[':'].jstree_contains = function(a,i,m){ 

     return (a.textContent || a.innerText || "").toLowerCase().indexOf(m[3].toLowerCase())>=0; 

    };