我在项目中使用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"}]}
答案 0 :(得分:2)
转发器重复数组。在你的回答中,你给它一个对象。该数组实际上是在employee属性上(在你的json响应中,也是因为isArray:false)