AngularJS-“全选"当前可见的项目 [英] AngularJS - "Select All" items that are currently visible

查看:111
本文介绍了AngularJS-“全选"当前可见的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试找出最好的方法来选择列表中当前可见的所有项目.

I am currently trying to figure out the best way to select all items in a list that are currently visible.

我目前在我的范围内有一个很大的项目列表,已对其应用分页,因此一次只能看到该列表中的几个项目.我有一个全选"按钮,在该按钮中,所需的行为是使它选择当前可见的所有项目-而不是列表中的所有项目.

I currently have a large list of items in my scope that has paging applied to it so only a few items of this list are visible at a time. I have a "Select All" button where the desired behavior is to have it select all the items that are currently visible - not all the items in the list.

我想我可以通过使用ng-init指令将可见项添加到控制器中的列表中来实现,然后可以使用该列表查看可见项.在我看来,似乎必须要有一个更好的解决方案,而我所缺少的.

I think I can achieve it by using the ng-init directive to add visible items to a list in the controller, I can then use that list to see what is visible. To me it seems that there has to be a better solution that I am missing.

有人对此有一个优雅的解决方案吗?

Does anyone have a elegant solution to this?

推荐答案

不是最清楚的问题,但我认为您使用的是带有某种过滤器的ng-repeat,它将某些项目分解为您想要的项目显示.您可以在声明ng-repeat时设置内联作用域变量,然后再执行此操作.

Not the clearest of questions, but I assume you're using an ng-repeat with some sort of filter that's knocking down the items to only the ones you want to show. You can set an inline scope variable when declaring your ng-repeat and work off of that.

因此,如果您的html看起来像这样:

So if your html looks like this:

<div ng-repeat="item in items | someFilter"></div>

您可以将其更改为:

<div ng-repeat="item in visibleItems = (items | someFilter)"></div>

然后,您可以在控制器内使用$scope.visibleItems,它将仅包含通过someFilter的项目的某些子集.

Then you can use $scope.visibleItems inside your controller and it will only contain the certain subset of items that have passed your someFilter.

这篇关于AngularJS-“全选"当前可见的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆