gpt4 book ai didi

angularjs - 在大数据集上使用多个过滤器进行 ng-repeat

转载 作者:行者123 更新时间:2023-12-02 21:55:27 25 4
gpt4 key购买 nike

我对 AngularJS 还很陌生,所以我只是尝试做一个简单的 CRUD 应用程序。目前,我使用 Controller MyCtrl1 处理的 div 中的 $http 提取数据(在 JSON 文件中)。

function MyCtrl1($scope, $http) {
$http.get('data/accounts.json').success(function(data) {
$scope.accounts = data;
...
});
}

div 内是一个 table,其中包含以下 tbody:

<tbody>
<tr ng-repeat="account in accounts | orderBy:sort.field:sort.desc | startFrom:currentPage * pageSize | limitTo:pageSize">
<td contentEditable="true" ng-repeat="(label, value) in account" ng-show="fields[label].visible">{{value}}</td>
</tr>
</tbody>

orderBy 过滤器根据选定的字段进行排序; startFrom 对数组进行切片以从某个点开始; limitTo 根据预设的页面大小进行过滤。如果没有分页过滤器,性能非常糟糕,但我想知道是否有其他方法可以解决这个问题?

我有 Chrome 版 Batarang,在“性能”选项卡下它显示 ngRepeatWatch 占用了最多时间,我认为这与我正在执行的所有过滤有关。

最佳答案

{{ expression | filter1 | filter2 }}

只需使用

<tr ng-repeat="account in accounts | filter1 | filter2 | filter3" >
<td contentEditable="true" ng-repeat="(label, value) in account" ng-show="fields[label].visible">{{value}}</td>
</tr>

Angular 2使用pipes ,但它看起来像过滤器:

<div>The chained hero's birthday is
<p>{{ birthday | date:'fullDate' | uppercase}}</p>
<div>

关于angularjs - 在大数据集上使用多个过滤器进行 ng-repeat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14126905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com