从 angularjs ng-repeat 表达式中获取重新排序的数组
Get the resorted array from angularjs ng-repeat expression
假设我有以下 angularjs 表达式
<tr ng-repeat="person in people | orderBy:age">
假设在我的控制器中,我想获得这个新排序列表中的前 5 个人。我该怎么做?
我希望有一些我可以检索的注入的 $scope 变量。
否则,我想在我的控制器中,我可以应用相同的排序并获得前五个,但应用排序两次似乎效率低下。无论如何,有人知道我在 javascript 中会怎么做吗?
当然,您可以使用此语法根据过滤器创建新变量:
ng-repeat="person in filtered = (people | orderBy:age)"
$scope.filtered
现在作为有序数组存在。
您可以使用 as
,它将 return 过滤后的数组作为范围变量:
<tr ng-repeat="person in people | orderBy:age as filteredPeople">
请注意,这在 angular
的早期版本中不可用
假设我有以下 angularjs 表达式
<tr ng-repeat="person in people | orderBy:age">
假设在我的控制器中,我想获得这个新排序列表中的前 5 个人。我该怎么做?
我希望有一些我可以检索的注入的 $scope 变量。
否则,我想在我的控制器中,我可以应用相同的排序并获得前五个,但应用排序两次似乎效率低下。无论如何,有人知道我在 javascript 中会怎么做吗?
当然,您可以使用此语法根据过滤器创建新变量:
ng-repeat="person in filtered = (people | orderBy:age)"
$scope.filtered
现在作为有序数组存在。
您可以使用 as
,它将 return 过滤后的数组作为范围变量:
<tr ng-repeat="person in people | orderBy:age as filteredPeople">
请注意,这在 angular
的早期版本中不可用