欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-05-14 19:55:13
index.html

index.html

<!doctype html> 
<html> 
<head> 
 <link 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: '复旦大学', 
   } 
  ]; 
 }); 

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