选择和访问在NG-重复项目 [英] Selecting and accessing items in ng-repeat

查看:107
本文介绍了选择和访问在NG-重复项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务对象的数组,我想在这样一个视图中显示

I have an array of objects in a service that I want to display in a view like this

<li ng-repeat="item in filteredItems = (resource.items | filter:multipleFilters...">
    <span class="title">{{item.escaped_name}}</span>
</li>

我想这些对象的选择是比较容易的部分。然后,我需要得到所选项目的数量,能够遍历所有的人来处理/更改数据。

I want these objects to be selectable which is the easy part. Then I'd need to get the count of the selected items and be able to iterate over all of them to process/change data.

什么是保存和访问所选项目的最佳方法是什么?

What is the best method to save and access the selected items?

请注意,所选的项目可能会改变,例如选择的项目可能跌至远,由于改变了过滤器。另外,我不想直接设置在数组中的对象选择的属性 - 对象数组是在服务和整个许多列表中的应用程序使用,我不想来清理选定的属性每个视图。

Note that the selected items could change, for example a selected item could fall away due to changed filters. Also, I don't want to set a selected property on the objects in the array directly - the array of objects is in a service and used throughout the app in many lists and I don't want to "clean up" the selected property for each view.

推荐答案

我通常包括 NG-点击标签:

<li ng-repeat="item in ..." ng-click="select_item(item)">

项目传递给 select_item()将成为用户选择的人。

The item passed to select_item() will be the one the user selected.

这篇关于选择和访问在NG-重复项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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