angularjs - 使用选择清除angularJS中的过滤器

标签 angularjs angularjs-filter

我在下面给出的 HTML 中使用了 ngOptions 指令:

<select ng-model="selectedGroupToShow.Id" ng-options="g.Id as g.Name for g in myGroups">
    <option value>-- All --</option>
</select>

我在 ng-repeat 中用来显示我的数据的过滤器是这样的:
filter:{GroupId:selectedGroupToShow.Id}"

即使我使用
filter:selectedGroupToShow

问题保持不变。重置过滤器..

这非常有效,但是当我想清除过滤器(选择默认选项 - 'All')时,它只会显示根本没有设置 GroupId 参数的数据。

在选择中选择默认选项元素时,如何显示所有数据(清除过滤器)?

最佳答案

我想我理解您的问题,您面临的问题是下拉列表选择为 --ALL-- 它的值为空而不是未定义。
因此,要重置它,您必须将其设置为未定义。

<div ng-repeat="item in items| filter:{itemId:selectedGroupToShow.Id||undefined}">
         {{item.itemId}}
</div>

请引用我为您的问题创建的以下 fiddle 。

fiddle

关于angularjs - 使用选择清除angularJS中的过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21830521/

相关文章:

angularjs - 偶尔 $compile :tpload errors

angularjs - 类型错误 : Cannot read property 'childNodes' of undefined in AngularJS directive

AngularJs 外部文件 Controller 和指令 : how to write them correctly?

javascript - 使用 AngularJS Filter 过滤数据。如何迭代对象?

javascript - 搜索过滤器不适用于具有通用模型的多个字段

angularjs - 关于使用 ionic 框架在本地保存数据的任何想法

javascript - 使用angularJS参数从div调用函数

javascript - 使用自定义过滤器 angularjs 过滤 2 个属性

javascript - 在 HTML 中按条件进行 Angular 自定义过滤不起作用

AngularJS - 通过另一个 ng-repeat 列表过滤 ng-repeat 列表