简体   繁体   English

limitTo 过滤前查询过滤的 ng-repeat 数据的长度

[英]Length of query-filtered ng-repeat data before limitTo filter

According to the accepted answer to this question , if I want to display the length of filtered ng-repeat data I would do:根据这个问题的公认答案,如果我想显示过滤后的 ng-repeat 数据的长度,我会这样做:

<div ng-repeat="person in filtered = (data | filter: query)">
</div>

Display the number of results:显示结果数:

Showing {{filtered.length}} Persons

My question is, how would I display the length of the data with that simple query filter when I am also using a limitTo filter:我的问题是,当我还使用limitTo过滤器时,如何使用该简单查询过滤器显示数据的长度:

<div ng-repeat="person in data | filter: query | limitTo: itemsPerPage">
</div>

To be clear, if there are 100 items resulting from data | filter: query需要明确的是,如果有 100 个项目来自data | filter: query data | filter: query and itemsPerPage = 10 , then in my case I want filtered.length to be 100, instead of the 10 I get from doing: data | filter: queryitemsPerPage = 10 ,那么在我的情况下,我希望filtered.length为100,而不是我从做的10:

<div ng-repeat="person in filtered = (data | filter: query) | limitTo: itemsPerPage">
</div>

Is there a way to get the length of the filtered results from an earlier filtering in the chain, while still applying more filters down the chain that potentially affect the length of the filtered results?有没有办法从链中较早的过滤中获得过滤结果的长度,同时仍然在链中应用更多可能影响过滤结果长度的过滤器?

I needed the same thing and am surprised no one ever answered this... but your last attempt got me 90% of the way, it just needs an extra pair of brackets:我需要同样的东西,很惊讶没有人回答这个问题……但是你的最后一次尝试让我成功了 90%,它只需要一对额外的括号:

<div ng-repeat="person in (filtered = (data | filter: query)) | limitTo: itemsPerPage">
</div>

To also get the final list, we can use an alias:为了获得最终列表,我们可以使用别名:

<div ng-repeat="person in (filtered = (data | filter: query)) | limitTo: itemsPerPage as visibleItems">
</div>

filtered will have the entire filtered list and visibleItems will have only those that are visible after the limitTo is applied. filtered将拥有整个过滤列表,而visibleItems将只拥有那些在应用limitTo 后可见的列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM