本文介绍了Angularjs:大于 ng-repeat 的过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在对 ng-repeat 标签应用大于过滤器.我编写了以下自定义过滤器函数:
$scope.priceRangeFilter = 函数(位置){返回 location.price >= $scope.minPrice;};
我在以下 HTML 代码中使用它:
更新 $scope.minPrice 时触发 ng-repeat 标签刷新的最佳方法是什么?
解决方案 应该是自动的.当 $scope.minPrice
改变时,中继器会自动更新.
function Ctrl($scope, $timeout) {$scope.map = [{名称:'地图1',价格:1}, {名称:'地图2',价格:2}, {名称:'地图3',价格:3}];$scope.minPrice = 0;$scope.priceRangeFilter = 函数(位置){返回 location.price >= $scope.minPrice;};$超时(函数(){$scope.minPrice = 1.5;}, 2000);}
I'm applying a greater than filter to a ng-repeat tag. I wrote the following custom filter function:
$scope.priceRangeFilter = function (location) {
return location.price >= $scope.minPrice;
};
and I use it in the following HTML code:
<div ng-repeat="m in map.markers | filter:priceRangeFilter">
What is the best way to trigger a refresh of the ng-repeat tag when $scope.minPrice is updated?
解决方案 It should be automatic. When $scope.minPrice
is changed, the repeater will be automatically updated.
function Ctrl($scope, $timeout) {
$scope.map = [{
name: 'map1',
price: 1
}, {
name: 'map2',
price: 2
}, {
name: 'map3',
price: 3
}];
$scope.minPrice = 0;
$scope.priceRangeFilter = function (location) {
return location.price >= $scope.minPrice;
};
$timeout(function () {
$scope.minPrice = 1.5;
}, 2000);
}
这篇关于Angularjs:大于 ng-repeat 的过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
08-24 19:11