我有我的角码有问题。角度过滤器复制阵列
我想过滤和使用角度过滤服务的数组,但是当我得到过滤数组过滤它重复,而不是采取数组中的每个元素,我已经尝试跟踪,但它似乎不是加工。
这是我的角的代码:
.filter('priceRange', function() {
return function(arr, range) {
if (!range) {return arr; }
var priceResult = [];
var pRange = range.split('-');
angular.forEach(arr, function(key, index) {
if (key.pPice >= pRange[0] && key.Price <= pRange[1]) {
priceResult.push(key);
}
})
console.log(arr);
return priceResult;
}
})
下面是我的HTML SEP起来:
<div class="col s12 m3" ng-repeat="car in [1,2,3,4,5] | priceRange" >
</div>
当我在过滤器部CONSOLE.LOG阵列我得到:
[1, 2, 3, 4, 5] rentTatu.js (line 66)
[1, 2, 3, 4, 5] rentTatu.js (line 66)
[1, 2, 3, 4, 5] rentTatu.js (line 66)
[1, 2, 3, 4, 5] rentTatu.js (line 66)
[1, 2, 3, 4, 5] rentTatu.js (line 66)
当我尝试用不同的数组我仍然得到数组的重复五tims
请检查此line-key.pPice> = pRange [0] && key.Price <= pRange [1],它有错误的变量名key.Price,它应该是key.pPrice。 –
@ Shailendra Singh Deol谢谢你的回答只是一个愚蠢的拼写错误... –