angularjs过滤器--filter与ng-repeat配合有奇效

树缝里也漏着一两点路灯光,没精打彩的,是渴睡人的眼。春尚浅,几处山顶上的梅花却挣扎着吐出红苞来。微风柔和地吹,柔和地爱抚我的面孔。荷塘里的荷花都羞涩地打着朵。落叶随着风高低起舞。

index.html

<!DOCTYPE html> 
<html> 
<head> 
 <link rel="nofollow noopener noreferrer" href="bootstrap.min.css" rel="external nofollow" rel="stylesheet"> 
</head> 
 
<body ng-app="myApp" ng-controller="myCtrl"> 
 <input type="text" placeholder="请输入学校ID 或 名称" ng-model="query"> 
<table class="table-bordered"> 
 <tr ng-repeat="school in schoolList | <strong>filter:query</strong>" > 
  <td class="col-md-2">{{ school.schoolId}}</td> 
  <td class="col-md-2">{{ school.schoolName}}</td> 
 </tr> 
 <script src="bootstrap.min.js"></script> 
 <script src="angular.min.js"></script> 
 <script src="script.js"></script> 
</table> 
</body> 
</html> 

script.js

angular.module('myApp', []) 
 .controller('myCtrl', function ($scope) { 
  $scope.schoolList = [ 
   { 
    schoolId: 01, 
    schoolName: '中山大学', 
   }, 
   { 
    schoolId: 02, 
    schoolName: '厦门大学', 
   }, 
   { 
    schoolId: 03, 
    schoolName: '北京大学', 
   }, 
   { 
    schoolId: 04, 
    schoolName: '复旦大学', 
   } 
  ]; 
 }); 

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!

您可能有感兴趣的文章
Ajax请求和Filter配合案例解析

JavaScript中filter的用法实例分析

Angular6 Filter实现页面搜索的示例代码

AngularJS使用Filter自定义过滤器控制ng-repeat去除重复功能示例

jquery的 filter()方法使用好代码教程