我已从v 1.0.8升级到Angular 1.2.9以帮助我的应用程序的性能。
我已经介绍了提高速度的轨道。
我曾经拥有的
<div class="result row"
data-ng-repeat="result in (filteredItems =
(results |
filter: filterPrice |
filter: filterCategories |
filter: filterTypes |
filter: filterAirConditioning |
filter: filterTransmission |
filter: filterFourByFour |
filter: filterFuelType |
filter: filterNumberOfDoors |
filter: filterOnAirport |
filter: filterFuelPolicy |
filter: filterUnlimitedMileage |
filter: filterFreeCancellation |
filter: filterTheftProtection |
filter: filterCDW |
filter: filterTaxesIncluded |
filter: filterProviders ) ) |
orderBy: [orderByOptions, orderByPriceLowToHigh, orderByPriority] |
limitTo: pageSize">
我现在拥有什么
<div class="result row"
data-ng-repeat="result in results |
filter: filterPrice |
filter: filterCarCategories |
filter: filterCarTypes |
filter: filterAirConditioning |
filter: filterTransmission |
filter: filterFourByFour |
filter: filterFuelType |
filter: filterNumberOfDoors |
filter: filterOnAirport |
filter: filterFuelPolicy |
filter: filterUnlimitedMileage |
filter: filterFreeCancellation |
filter: filterTheftProtection |
filter: filterCDW |
filter: filterTaxesIncluded |
filter: filterProviders |
orderBy: [orderByOptions, orderByPriceLowToHigh, orderByPriority] |
startFrom: currentPage*pageSize |
limitTo: pageSize track by $index">
我有分页查找filterItems的长度。那不再存在。此外,其他一些JS需要filteredItems进行日志记录,分析等
在HTML视图中,我可以在应用过滤器后得到ng-repeat的长度
{{(results |
filter: filterPrice |
filter: filterCarCategories |
filter: filterCarTypes |
filter: filterAirConditioning |
filter: filterTransmission |
filter: filterFourByFour |
filter: filterFuelType |
filter: filterNumberOfDoors |
filter: filterOnAirport |
filter: filterFuelPolicy |
filter: filterUnlimitedMileage |
filter: filterFreeCancellation |
filter: filterTheftProtection |
filter: filterCDW |
filter: filterTaxesIncluded |
filter: filterProviders)
.length}}
这有点拗口,但确实返回了我想要的数字。如何将其传递给$ scope?
答案 0 :(得分:40)
您可以创建一个包含已过滤数组的中间变量:
data-ng-repeat="result in filteredResults = (results | filter:filterPrice | filter:filterCarCategories | etc.)"
然后可以使用:
filteredResults.length