AngularJS - “Select All” items that are currently visible

假如想象 提交于 2019-12-10 10:37:00

问题


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.

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?


回答1:


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.

So if your html looks like this:

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

You can change it to:

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

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



来源:https://stackoverflow.com/questions/23704743/angularjs-select-all-items-that-are-currently-visible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!