Angular中怎么自定义模糊查询,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
具体代码如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>www.jb51.net Angular模糊查询、排序</title> <style> *{ margin: 0; padding: 0; } table{ border-collapse: collapse; } td{ padding: 10px; border: 1px solid #000; } .top{ display: inline-block; width: 0; height: 0; border: 10px solid transparent; border-top:10px solid red; } .bot{ display: inline-block; width: 0; height: 0; border: 10px solid transparent; border-bottom:10px solid red; } </style> <script src="angular.min.js"></script> <script> var myapp=angular.module("myapp",[]); myapp.controller("myCtrl",function ($scope) { var userInfo=[ {name:"marry",salary:12345,sex:"girl",birthday:1505111954735}, {name:"Lily",salary:12425,sex:"girl",birthday:1505711954735}, {name:"Jeny",salary:87145,sex:"girl",birthday:1505811954735}, {name:"Rose",salary:23845,sex:"girl",birthday:1905111954735}, {name:"Tom",salary:86565,sex:"boy",birthday:1575111994735} ]; $scope.arr=userInfo; /*自定义的模糊查询*/ $scope.search=""; $scope.searchFun=function(obj){ if($scope.search!=""){ if(obj.name.toLowerCase().indexOf($scope.search.toLowerCase())!=-1){ return true; }else{ return false; } }else{ return true; } }; /* 排序*/ $scope.sort="name"; $scope.revers=false; $scope.sortFun=function (column) { if($scope.sort==column){ $scope.revers=!$scope.revers; }else{ $scope.revers=false; } $scope.sort=column; }; $scope.getClass=function(column){ if($scope.sort==column){ if($scope.revers==false){ return "top" }else{ return "bot" } } } }) </script> </head> <body ng-app="myapp" ng-controller="myCtrl"> <input type="text"ng-model="search"> <table> <thead> <th>编号</th> <th ng-click="sortFun('name')">姓名<span ng-class="getClass('name')"></span></th> <th ng-click="sortFun('salary')">薪资<span ng-class="getClass('salary')"></span></th> <th ng-click="sortFun('sex')">性别<span ng-class="getClass('sex')"></span></th> <th ng-click="sortFun('birthday')">生日<span ng-class="getClass('birthday')"></span></th> </thead> <tbody> <tr ng-repeat="item in arr|filter:searchFun:value|orderBy:sort"> <td>{{$index}}</td> <td>{{item.name|uppercase}}</td> <td>{{item.salary|currency:'$'}}</td> <td>{{item.sex}}</td> <td>{{item.birthday|date:'yyyy-MM-dd'}}</td> </tr> </tbody> </table> </body> </html>
看完上述内容,你们掌握Angular中怎么自定义模糊查询的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。