Ok I have a ng-repeat:
<div id="scrolltwo" class="animate-repeat panel" ng-repeat="items in arrayfull |filter:filtertype ">
and in filtertype i have:
[[0] => "Typeone", [1] => "Typetwo" ]
how do i get the filter to iterate across the whole array and match results that match the values?
UPDATE with custom filter:
<div id="scrolltwo" class="animate-repeat panel" ng-repeat="items in arrayfull | array | filter:matchaccnttypes(accnttypes)">
Array filter which works:
.filter('array', function() {
return function(items) {
console.log(items);
var filtered = [];
angular.forEach(items, function(item) {
filtered.push(item);
});
return filtered;
};
})
matchaccountypes which doesn't!:
$scope.matchaccnttypes = function matchaccnttypes(query) {
return function(items) {
return items.Organtype.match(query);
angular.forEach($scope.accnttypes, function(value, key){
console.log(key + ': ' + value);
});
}
};
it just returns the last value passed into the $scope.accntypes array which is my sample array above..
A custom filter with the help of underscoreJS. Here is the Fiddle .
app.filter('arrayFilter', function() {
return function(input, filterType) {
return _.intersection(input,filterType);
};
});
Without UnderscoreJS
app.filter('arrayFilter', function() {
return function(input, filterType) {
var filterdArray =[];
angular.forEach(input, function(inputValue, key){
angular.forEach(filterType, function(filterTypeValue, key){
if(inputValue==filterTypeValue){
filterdArray.push(inputValue);
}
});
});
return filterdArray;
};
});
and ng-repeat
should be used in the following way.
ng-repeat="array in arrayfull | arrayFilter : filterType"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.