【发布时间】:2015-03-11 20:49:29
【问题描述】:
我有一个 ng-repeat,里面有多个 ng-show 条件。像这样的东西(虚构的例子):
<ul>
<li ng-repeat="item in items | filter:searchFilter" >
<label ng-show="item.label==1">{{item.label}}</label>
<label ng-show="item.label==2">{{item.label}}</label>
<label ng-show="item.label==3">{{item.label}}</label>
<label ng-show="item.label==4">{{item.label}}</label>
<label ng-show="item.label==5">{{item.label}}</label>
<label ng-show="item.label==1">{{item.label}}</label>
<label ng-show="item.label==2">{{item.label}}</label>
<label ng-show="item.label==1">{{item.label}}</label>
</li>
</ul>
我正在使用 ng-show 进行格式化,例如:
我想在 item.cellphone 不为空时显示手机列...
我有一个大数据源(+1000 行),并且在使用过滤器时发现了性能问题。
如果我去掉大部分 ng-show 条件,性能还是不错的。这是一个活生生的例子:
我知道您可以使用“track by”(here's an topic about it) 来提高性能,但看起来它不足以使过滤器“平滑”(至少,不会太迟钝)。
有没有办法提高具有多个 ng-show 条件和大数据源的 ng-repeat 的过滤性能?
【问题讨论】:
-
你的行和手表太多了。一些关于 Angular 性能的帖子说你不应该拥有超过 2000 块手表。在您的示例中,您至少有 4500 * 7!您需要分页等。
标签: javascript angularjs