ng-repeat : 按单个字段过滤 [英] ng-repeat :filter by single field

查看:32
本文介绍了ng-repeat : 按单个字段过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列产品,我正在重复使用 ng-repeat 并且正在使用

按颜色过滤这些产品.过滤器正在工作,但如果产品名称/描述等包含颜色,则应用过滤器后产品仍然存在.

如何将过滤器设置为仅应用于数组的颜色字段而不是每个字段?

解决方案

参见 过滤页面.使用一个对象,并在 color 属性中设置颜色:

按颜色搜索:<div ng-repeat="product in products | filter:search">

I have an array of products that I'm repeating over using ng-repeat and am using

<div ng-repeat="product in products | filter:by_colour"> 

to filter these products by colour. The filter is working but if the product name / description etc contains the colour then the product remains after the filter is applied.

How do I set the filter to only apply to the colour field of my array rather than every field?

解决方案

See the example on the filter page. Use an object, and set the color in the color property:

Search by color: <input type="text" ng-model="search.color">
<div ng-repeat="product in products | filter:search"> 

这篇关于ng-repeat : 按单个字段过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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