Angular 学习笔记——ng-repeat&filter
<!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <meta charset="UTF-8"> <title>Document</title> <script type="text/javascript" src="js/angular-1.3.0.js"></script> <script> var m1 = angular.module('myApp',[]); m1.controller('may',['$scope','$filter',function($scope,$filter){ var oriArr = [ { name : "red" , age : "20" }, { name : "yellow" , age : "40" }, { name : "blue" , age : "30" }, { name : "green" , age : "10" } ]; $scope.datelist = oriArr; $scope.fnSort = function(arg){ arguments.callee['fnSort'+arg] = !arguments.callee['fnSort'+arg] $scope.datelist = $filter('orderBy')($scope.datelist,arg,arguments.callee['fnSort'+arg]); }; $scope.filterfind = function (){ $scope.datelist = $filter('filter')(oriArr,$scope.filterVal); } }]) </script> </head> <body ng-controller='may'> <input type="text" ng-model="filterVal"><button ng-click="filterfind()">search</button> <table border="1"> <tr> <th ng-click="fnSort('name')">姓名</th> <th ng-click="fnSort('age')">年龄</th> </tr> <tr ng-repeat="date in datelist"> <td>{{date.name}}</td> <td>{{date.age}}</td> </tr> </table> </body> </html>