通过ng-repeat错误显示2个数组

时间:2014-02-19 09:12:06

标签: arrays angularjs

我正在尝试从AngularJS中的2个数组创建一个表,一个数组包含Employees名称,其他数组包含Services Name,其余单元格包含复选框但是当我这样做时出现错误Error: [ngRepeat:dupes]

这是我的AngularJS代码

     var model = angular.module('wizard', ['ngRoute'])
    .config(["$routeProvider", function ($routeProvider) {
        $routeProvider.when("/m5", {
            controller: "model5Controller",
            templateUrl: "/templates/m5.html"
        });

        $routeProvider.otherwise({ redirectTo: '/' });
    }]);

    var model5Controller = ["$scope", "$http", "$window", function ($scope,
 $http, $window) {
    $scope.PBA = [];
    $scope.SOB = [];

    $http.get('/Test/GetPBA').
        then(
        function (result) {
            //success
            $scope.PBA = result.data;
        },
        function () {
            //error
        });

    $http.get('/Test/GetSOB').
        then(
        function (result) {
            //success
            $scope.SOB = result.data;
        },
        function () {


    //error
    });

    $scope.save = function () {
//to be written
    };
    }];

GetPBA / GetSOB返回JSON类型Array of List 两者都包含Id,Name

等属性

这是我的HTML

<div>
<form ng-submit="save()">
    <table border="1">
        <tr>
            <td><strong>Services</strong></td>
            <td ng-repeat="e in PBA">{{e.Name}}</td>
        </td>
        <tr ng-repeat="i in SOB">
            <td>{{i.Name}}</td>
            <td ng-repeat="e in PBA">
                <input type="checkbox" name="{{e.Id}}" />
            </td>
        </tr>
    </table>
</form>

1 个答案:

答案 0 :(得分:1)

试试这个

<tr ng-repeat="i in SOB track by $index">
      <td>{{i.Name}}</td>
      <td ng-repeat="e in PBA track by $index">
          <input type="checkbox" name="{{e.Id}}" />
      </td>
</tr>