NG-重复滤波器QUOT;显示所有的"如果没有选择的过滤项 [英] ng-repeat filter "show all" items if no filter selected

查看:151
本文介绍了NG-重复滤波器QUOT;显示所有的"如果没有选择的过滤项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用℃的 NG-重复过滤器;选择> 菜单通过一堆过滤国家。

I have an ng-repeat filter that uses a <select> menu to filter through a bunch of countries.

例如:

<div class="col-md-3 col-sm-6" ng-repeat="item in listings | filter: { location: locationFilter }">

我怎样才能让这个如果没有被选中,它会自动显示所有的国家呢?而且,只有开始过滤一次,某一个国家选择?

How can I make it so that if nothing is selected, it automatically shows ALL the countries? And only starts filtering once a particular country is selected?

我敢肯定,这可能是一个简单的问题,但我很新的这一点,并不能找到如何做到这一点。

I'm sure this is probably a simple question but I am quite new to this and couldn't find how to do it.

谢谢!

推荐答案

如果过滤前pression返回未定义,那么过滤器将不适用。所以,你可以不喜欢以下内容:

If the filter expression returned undefined, then the filter would not apply. So, you could do something like the following:

<div ng-repeat="item in listings | filter:(!!locationFilter || undefined) && {location: locationFilter}">
   {{item}}
</div>

!! locationFilter 手柄,falsy和未定义值)

(!!locationFilter handles '', falsy and undefined values)

plunker

这篇关于NG-重复滤波器QUOT;显示所有的&QUOT;如果没有选择的过滤项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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