AngularJs, filter case insensitive

后端 未结 2 723
遇见更好的自我
遇见更好的自我 2020-12-06 18:13

I\'ve got an json full of datas with lowcase and upcase. For example :

[

  { \"firstName\":\"JoHn\" , \"lastName\":\"DoE\" }, 
  { \"firstName\":\"aNnA\" ,          


        
相关标签:
2条回答
  • 2020-12-06 18:36

    There is a way to turn on case insensetive filter:

    <div data-ng-repeat="item in items | filter : searchText : false"></div>
    

    Plunker

    0 讨论(0)
  • 2020-12-06 18:42

    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

    0 讨论(0)
提交回复
热议问题