我在一个项目中使用 AngularJS。在我看来,我重复了一些员工并将他们展示在屏幕上。那行得通,但我必须使用代码
<li ng-repeat="employee in employees.employee">
代替
<li ng-repeat="employee in employees">
为什么我不能直接访问员工以遍历不同的 json 对象?
我的项目代码片段:
控制器
Test.controller('EmployeeListController', function($scope, Employee) {
$scope.employees = Employee.query();
});
HTML 视图
<ul>
<li ng-repeat="employee in employees.employee">
<a href="mailto:{{employee.email}}" title="{{employee.email}}">{{employee.firstName}} {{employee.lastName}} ({{employee.email}})</a>
</li>
</ul>
工厂
Test.factory('Employee', function ($resource) {
return $resource('/TestServer/rest/employees/:employeeId', {}, {
update: {method:'PUT'},
query: {method:'GET', isArray:false}
});
});
JSON 响应
{"employee":[{"created":null,"description":"TestDescription","email":"TestMail","firstName":"TestFirstName","id":"1","image":"TestImage.jpg","lastModification":null,"lastName":"TestLastName","phone":"121212121212"},{"created":null,"description":"TestDescription","email":"TestEmail","firstName":"TestFirstName","id":"2","image":"TestImage2.jpg","lastModification":null,"lastName":"TestLastName","phone":"2124343434"}]}