我有一个简单的数组过滤器。数组中的每个项目都有一个“ Rating”属性,该属性是一个数字。值可以是-3,-2,-1,1,2,3。
如果我这样做
$scope.ratingFilter = -3; // negative numbers work fine
但我愿意
$scope.ratingFilter = 3; // positive numbers are showing items that have a Rating of 3 AND -3. Why are negative number appearing in the filter???
$scope.updateMarkers = function(){
var filters = [];
if($scope.ratingFilter != 'all'){
filters.Rating = $scope.ratingFilter;
}
var arr = [];
angular.forEach($scope.allMarkers, function(value, key){
arr.push(value);
});
$scope.markers = $filter('filter')(arr, filters);
}
答案 0 :(得分:0)
考虑使用普通的JavaScript在控制器中自己过滤数组:
$scope.markers = arr.filter(x => x.Rating === ratingFilter);
答案 1 :(得分:0)
在true
中将'strict'值设置为$filter
。
$filter('filter')(arr, filters, true);
答案 2 :(得分:0)
$ scope.dsset = $ filter('filter')($ scope.array,{id:1});