AngularJS过滤器完全匹配 [英] AngularJS Filter Exact Match

查看:118
本文介绍了AngularJS过滤器完全匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过分类筛选项目的清单。我希望用户能够点击一个按钮,然后对其应用列表中的过滤器。

I need to filter a list of items by their category. I want the user to be able to click a button, and then have the filter applied to a list.

目前,我有这样的工作在一定程度上。

At the moment, I have this working to an extent.

让说,例如我有电影列表,呈现像这样:

Let's say for example I have a list of movies, rendered like so:

<li ng-repeat="movie in movieList | filter:filters">{{ movie.title }}</li>

和我也有电影类型的列表(呈现为按钮,点击它会过滤电影列表时),呈现像这样:

And I also have a list of movie genres (rendered as buttons, which when clicked will filter the list of movies) rendered like so:

<li ng-repeat="genre in genres">
    <a ng-click="filters.genre = genre.name" ng-click='changeGenre(genre.name)'>{{genre.name}}</a>
</li>

(所有'changeGenre()函数确实是更新的范围,以显示当前正在查看的流派)。

(All the 'changeGenre()' function does is update the scope to show which genre is currently being viewed).

现在,直到我有一个情况,说我有2个流派能正常工作了。当我通过与流派操作电影筛选,我不仅拿到的动作片名单,同时也动作冒险电影。

Now this works fine up until I have a situation where, say I have the 2 genres: 'Action' and 'Action Adventure'. When I filter by movies with the genre 'Action', I not only get a list of Action movies, but also Action Adventure movies.

有没有一种方法,我可以使用过滤器得到一个精确匹配?

Is there a way I can get an exact match using the filter?

推荐答案

这是目前在过滤器中提供的本机。您只需通过真实的过滤器,使严格的匹配。

This is now provided natively within the filter. You can just pass true to the filter to enable strict matching.

<li ng-repeat="movie in movieList | filter : filters : true">{{ movie.title }}</li>

Refereces

Refereces

<一个href=\"https://docs.angularjs.org/api/ng/filter/filter\">https://docs.angularjs.org/api/ng/filter/filter

<一个href=\"http://stackoverflow.com/a/18243147/1466430\">http://stackoverflow.com/a/18243147/1466430

这篇关于AngularJS过滤器完全匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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