在使用select angularJS清理过滤器 [英] clearing filter in angularJS using select
问题描述
我用HTML中ngOptions指令如下:
I use the ngOptions directive in the HTML given below:
<select ng-model="selectedGroupToShow.Id" ng-options="g.Id as g.Name for g in myGroups">
<option value>-- All --</option>
</select>
我正在使用NG-重复,以显示我的数据的过滤器是这样的:
The filter I am using in ng-repeat to show my data goes like this:
filter:{GroupId:selectedGroupToShow.Id}"
即使我用
filter:selectedGroupToShow
问题停留在same.Resetting过滤器..
the issue stays the same.Resetting the filter..
这完美的作品,但是当我想要清除过滤器(选择默认选项 - 全部),它只会显示不具有的的GroupId 的参数设置的所有数据。
This works perfectly, but when I want to clear the filter (select default option - 'All') it will only show data that doesn't have GroupId parameter set at all.
我怎么能显示所有的数据中选择选择默认选项元素时(清除过滤器)?
How can I show ALL the data (clear the filter) when choosing default option element within select?
推荐答案
我想我明白你的问题,当选择下拉菜单--ALL--其值为null,而不是不确定的,你所面临的问题。
因此,要重置你必须将其设置为未定义。
I think I understand your problem and the issue you are facing is when dropdown selected to --ALL-- its value is null and not undefined. So to reset it you have to set it for undefined.
<div ng-repeat="item in items| filter:{itemId:selectedGroupToShow.Id||undefined}">
{{item.itemId}}
</div>
请参考下面捣鼓我为你的问题产生。
Please refer the below fiddle I have created for your problem.
这篇关于在使用select angularJS清理过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!