製造小提琴角過濾:http://jsfiddle.net/L3wra2kL/1/單輸入和多條件
我希望是這樣的: 搜索:「房子巴黎」 - >此行的結果:Sell house in Paris
我真的不知道該怎麼做:單獨的單詞,並讓他們成爲'OR條件是爲了我的過濾器...
任何想法?
製造小提琴角過濾:http://jsfiddle.net/L3wra2kL/1/單輸入和多條件
我希望是這樣的: 搜索:「房子巴黎」 - >此行的結果:Sell house in Paris
我真的不知道該怎麼做:單獨的單詞,並讓他們成爲'OR條件是爲了我的過濾器...
任何想法?
您可以製作自己的自定義過濾器。下面是一個簡單的實現這個你提供
過濾器的示例性一體化的一個例子
app.filter('contains', ['$filter', function(filter) {
return function (collection, query) {
var arr = query ? query.toLowerCase().split(/\s+/) : [];
for (var i = 0; i < arr.length; i += 1) {
collection = filter('filter')(collection, arr[i]);
}
return collection;
}
}]);
完美的解決方案。謝謝。 – Tyvain
你可以看搜索的變化,如果有新的價值 - 只要拆將其轉化爲單詞並通過這個單詞過濾原始數組。
<div ng-app="app">
<div ng-controller="AppCtrl">
<p>Name: <input type="text" ng-model="search"></p>
<ul>
<li ng-repeat="x in articles">
{{ x }}
</li>
</ul>
</div>
</div>
角碼:
(function(angular){
angular.module('app',[])
.controller('AppCtrl', function($scope, $filter){
$scope.articlesOriginal = ['Sell house in Washigton', 'Sell house in Paris', 'Sell car in London', 'Sell car in Washigton'];
$scope.articles = $scope.articlesOriginal;
$scope.$watch('search', function(newVal, oldVal){
if(newVal!==oldVal){
var filteredList, splitedWords, resultList=$scope.articlesOriginal;
splitedWords = newVal.trim().split(/\s+/);
angular.forEach(splitedWords, function(word){
resultList = $filter('filter')(resultList, word);
});
$scope.articles = resultList;
}
});
});
})(angular);
看看這個答案。它本質上需要做出自己的過濾 http://stackoverflow.com/questions/20459798/angularjs-filter-for-multiple-strings – prawn