【问题标题】:Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys不允许在转发器中重复。使用“track by”表达式指定唯一键
【发布时间】:2017-01-27 20:09:55
【问题描述】:

这里我正在尝试通过 Angular Js 从 Mvc 中的 Wcf-Rest 服务访问数据但是当我尝试绑定数据时,它通过错误作为错误:[ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: ee in HelloData, Duplicate key: string:r, Duplicate value: r

<table class="table table-bordered table-hover tab-content">
            <tr>
                <th><b>Id</b></th>
                <th><b>Name</b></th>
               </tr>
            <tr ng-repeat="ee in HelloData"> 
                <td>{{ee.Id}}</td>
                <td>{{ee.Name}}</td>

            </tr>
        </table>

Ctrl.Js

$scope.CallServiceDb = function () {
            alert('in cntrl');
            var sss = MywcfService.GetData();
            sss.then(function (d) {
                $scope.HelloData = d.data;
            })

Service.Js

 var RestApi = "http://localhost:9706/EmployeeService.svc";

this.GetData = function () {
        alert('in Service');
        var sss = $http({
            url: RestApi+"/Hell",
            method: "GET",
         })
        return sss;
    }

【问题讨论】:

    标签: angularjs


    【解决方案1】:

    如果您的数据源有重复的标识符,您可以通过 $index 进行跟踪,

    <tr ng-repeat="ee in HelloData track by $index"> 
       <td>{{ee.Id}}</td>
       <td>{{ee.Name}}</td>
    </tr>
    

    【讨论】:

    猜你喜欢
    • 2017-05-12
    • 1970-01-01
    • 1970-01-01
    • 2016-03-05
    • 2014-06-17
    • 2015-03-02
    • 1970-01-01
    • 1970-01-01
    • 2014-05-10
    相关资源
    最近更新 更多