我需要按班级过滤学生,然后将其推到HTML
模式。
以下是代码:http://plnkr.co/edit/GG9EYmPlIyD4ZM0ehaq6?p=preview
html的:
<div ng-controller="ClassController">
<table>
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="student in students">
<td>{{ student.name }}</td>
</tr>
</tbody>
</table>
</div>
的.js:
var app;
app = angular.module('App', []);
app.controller('ClassController', [
'$scope', '$http', function($scope, $http) {
$scope.students = [];
return $http.get('data.json').then(function(result) {
return angular.forEach(result.data, function(item) {
return $scope.students.push(item);
});
});
}
]);
您可以在链接
上找到.json
文件
答案 0 :(得分:0)
这是你的控制器:
var app;
app = angular.module('App', []);
app.controller('ClassController', [
'$scope', '$http', function($scope, $http) {
var someFilter = 'taple';
$scope.students = [];
return $http.get('data.json').then(function(result) {
$scope.students = result.data.filter(function(item) {
return item.classroom.school.name.toLowerCase().indexOf(someFilter) > -1;
})
});
}
]);