2013-11-05 26 views

回答

10

我不知道任何內置過濾器,將執行OR般的搜索。您可以定義自己的過濾器,將滿足您的需求:

angular.module('App', []).filter('search', function($filter){ 
    return function(items, text){ 
     if (!text || text.length === 0) 
     return items; 

     // split search text on space 
     var searchTerms = text.split(' '); 

     // search for single terms. 
     // this reduces the item list step by step 
     searchTerms.forEach(function(term) { 
     if (term && term.length) 
      items = $filter('filter')(items, term); 
     }); 

     return items 
    }; 
}); 

使用,查看該代碼這個Plunkr:simple OR search filter

+0

,就像我們用戶想要的那樣工作,當我們搜索生活在精確城市的亞歷克斯時,它是有幫助的......非常感謝 –

+0

我需要通過添加過濾器來添加過濾器。 –