Ari*_*ing 1 angularjs angularjs-filter
我试图像这个plunker一样制作angularjs全文搜索
http://plnkr.co/edit/PwcteF6WAtuAOj3ZDKLe?p=preview
我尝试了很多组合但没有效果..
例如,我想搜索像'alex big-mary'或'alex 800'或'mary big'这样的交叉列但是没有作品alex 555有效,因为555存在于alex字后面
小智 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
};
});
Run Code Online (Sandbox Code Playgroud)
使用此Plunkr:simple OR搜索过滤器查看此代码的实际操作
| 归档时间: |
|
| 查看次数: |
3818 次 |
| 最近记录: |