简体   繁体   English

循环到ng-repeat中的可见项

[英]Loop to visible items in ng-repeat

It is possible to loop to the visible items in a ng-repeat? 是否可以循环到ng-repeat中的可见项? I have a ng-repeat with multiple filters and I want to create a 'select all' function to select all the visible items in the repeat. 我有一个带有多个过滤器的ng-repeat,我想创建一个“全选”功能以选择重复中的所有可见项。

How can I get the visible items? 如何获得可见物品? The selection may be come undone when the filter is changing, so there are no 'old' selections possible, but that can be easily done to loop all items with no conditional. 更改过滤器时,该选择可能会撤消,因此不可能有“旧的”选择,但是可以轻松地无条件循环所有项目。

<div class="item" ng-repeat='item in collection | product_sex:filter_sex | product_stock: stockKind | filter:productFilter'>
    {{item.name}}
    {{item.price}}
</div>

you can add a filter like this; 您可以添加这样的过滤器;

<div ng-repeat="item in items | filter:{visible: true} ">
    <p>{{item.id}}</p>
</div>

You could define a variable that represents all visible items by using as expression with a ng-repeat directive: 您可以定义通过使用用NG-重复指令表达代表了所有可见的项目变量:

<div class="item" 
     ng-repeat='item in (collection | product_sex:filter_sex | product_stock: stockKind | filter:productFilter) as allVisibleItems'>
    {{item.name}}
    {{item.price}}
</div>

You could access this variable easily, right underneath ng-repeat for example: 您可以在ng-repeat下方轻松访问此变量,例如:

<div ng-click="selectAll(allVisibleItems)">Select all Items</div>

More can be read here: https://docs.angularjs.org/api/ng/directive/ngRepeat 可以在这里阅读更多内容: https : //docs.angularjs.org/api/ng/directive/ngRepeat

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

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