admin管理员组文章数量:1290186
I've got an json full of datas with lowcase and upcase. For example :
[
{ "firstName":"JoHn" , "lastName":"DoE" },
{ "firstName":"aNnA" , "lastName":"smIth" },
{ "firstName":"PeTer" , "lastName":"JOnes" }
]
And I've got something similar to this :
Search: <input ng-model="searchText">
<table id="searchTextResults">
<tr><th>Name</th><th>Phone</th></tr>
<tr ng-repeat="friend in friends | filter:searchText">
<td>{{friend.firstName}}</td>
<td>{{friend.lastName}}</td>
</tr>
</table>
What I want to do is to search a friend without looking at upcases and lowcases. So basically when I type "John", "JOHN" or simply "john" in my input, it should return my friend John.
So is it possible to apply a case insensitive option to a filter ?
I've got an json full of datas with lowcase and upcase. For example :
[
{ "firstName":"JoHn" , "lastName":"DoE" },
{ "firstName":"aNnA" , "lastName":"smIth" },
{ "firstName":"PeTer" , "lastName":"JOnes" }
]
And I've got something similar to this :
Search: <input ng-model="searchText">
<table id="searchTextResults">
<tr><th>Name</th><th>Phone</th></tr>
<tr ng-repeat="friend in friends | filter:searchText">
<td>{{friend.firstName}}</td>
<td>{{friend.lastName}}</td>
</tr>
</table>
What I want to do is to search a friend without looking at upcases and lowcases. So basically when I type "John", "JOHN" or simply "john" in my input, it should return my friend John.
So is it possible to apply a case insensitive option to a filter ?
Share Improve this question edited Mar 23, 2016 at 21:23 Tim Gautier 30.1k5 gold badges48 silver badges53 bronze badges asked Aug 6, 2013 at 13:45 user2462805user2462805 1,0693 gold badges12 silver badges29 bronze badges2 Answers
Reset to default 19There is a way to turn on case insensetive filter:
<div data-ng-repeat="item in items | filter : searchText : false"></div>
Plunker
Pass a function name to filter
which you define on an applicable scope, where you use string's toLowerCase. See ngFilter. The function signature is a simple function (item) { ... }
.
Example JS in your controller:
$scope.filterOnlyFoo = function (item) {
return item == "foo";
}
Example HTML:
<div data-ng-repeat="item in items | filter: filterOnlyFoo"></div>
Sample Plunker
本文标签: javascriptAngularJSfilter case insensitiveStack Overflow
版权声明:本文标题:javascript - AngularJs, filter case insensitive - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738345574a2077997.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论