AngularJs ng-Repeat Filter停止使用“!"搜索 [英] AngularJs ng-Repeat Filter stop working on search with "!"

查看:123
本文介绍了AngularJs ng-Repeat Filter停止使用“!"搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ng_repeat的AngularJS过滤器在搜索文本!"时不起作用. 就像搜寻文字是!icon".然后返回不包含"icon"的结果. 我也尝试过angularjs.org.

AngularJS Filter of ng_repeat Doesn't work while searching with text "!". like searching text is "!icon". then it return result that don't contain "icon". i have also tried on angularjs.org.

https://docs.angularjs.org/api/ng/directive/ngRepeat

当我搜索"28"时,它仅填充两个结果,但是当我搜索!28"时,它返回不包含28的8个结果.

when i search "28" then it populates only two results but when i search "!28" then it return 8 result that dont contain 28.

有什么办法可以考虑!"作为正常字符.

Is there any way to considered "!" as a normal character.

推荐答案

ng-repeat中的过滤器的行为与

The filter in ng-repeat behaves exactly as specified in filter

该字符串用于与数组的内容进行匹配.将返回所有字符串或数组中具有字符串属性的对象与此字符串匹配的对象.这也适用于嵌套对象属性.可以通过在字符串前面加上!

The string is used for matching against the contents of the array. All strings or objects with string properties in array that match this string will be returned. This also applies to nested object properties. The predicate can be negated by prefixing the string with !

您可以找到角度比较代码这里.我相信没有简单的解决方法-它不是正则表达式,代码仅检查!是否为第一个字符.甚至自定义比较器也无法正常工作,因为!仍会取反.

You can find the angular comparison code here. I believe there is no simple workaround - it's not a regexp, the code only checks whether ! is the first character. Even a custom comparator won't work cause the ! will still do a negation.

最简单的解决方法是创建自己的$ filter进行过滤,并停止使用filter过滤器.

The easiest workaround is to create your own $filter for filtering and stop using the filter filter.

这篇关于AngularJs ng-Repeat Filter停止使用“!"搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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