AngularJs ng-Repeat 过滤器停止使用“!"进行搜索 [英] AngularJs ng-Repeat Filter stop working on search with "!"
问题描述
ng_repeat 的 AngularJS 过滤器在搜索文本!"时不起作用.就像搜索文本是!图标".然后它返回不包含图标"的结果.我也试过 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"时,它返回 8 个不包含 28 的结果.
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 过滤器停止使用“!"进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!