使用AngularJS过滤表

时间:2017-03-02 21:58:43

标签: javascript angularjs filter html-table

我还有一个AngularJS控制器,如下所示:

app.controller('StudentController', ['$scope', function($scope) {
   $scope.filter: {
      hobby: {
        football: false,
        tennis: false,
        soccer: false
     }
   }
   $scope.students: [
      {   
         name: John,
         hobby: [soccer, football, tennis]
      },
      {
         name: James,
         hobby: [soccer, tennis]
      }
  ]
]);

在HTML方面,我有一些复选框和一个显示学生表的表格:

<input type="checkbox" ng-model="filter.hobby.soccer"><label>Soccer</label>
<input type="checkbox" ng-model="filter.hobby.tennis"><label>Tennis</label>
<input type="checkbox" ng-model="filter.hobby.football"><label>Football</label>

<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Hobbies</th>
    </tr>
  </thead>
  <tbody ng-repeat="student in students">
    <tr ng-hide="rotation.hideRotation">
      <td>{{ student.name }}</td>
      <td>{{ student.hobby.join(', ')  }}</td>
    </tr>
  </tbody>
</table>

我想知道如何使用AngularJS过滤表格。例如,当我点击复选框来过滤足球时,只会出现詹姆斯。

1 个答案:

答案 0 :(得分:0)

首先,您的json不正确,应该是:

BinaryWriter(Stream output, Encoding encoding, bool leaveOpen)

答案是{ "students": [ { "name": "John", "hobby": [ {"sport": "soccer"}, {"sport": "football"}, {"sport": "tennis"} ] }, { "name": "James", "hobby": [ {"sport": "soccer"}, {"sport": "tennis"} ] } ] } 循环:

angular.ForEach