0

我在一个项目中使用 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"}]}
4

1 回答 1

2

中继器在阵列上重复。在你的回应中,你给了它一个对象。该数组实际上位于员工属性上(在您的 json 响应中,也因为 isArray: false)

于 2013-03-08T10:15:39.920 回答