【问题标题】:Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed错误:[ngRepeat:dupes] 不允许在转发器中重复
【发布时间】:2015-03-18 16:03:25
【问题描述】:

我有类似here 描述的情况,但我使用 $http 调用来获取我的数据以构建无限滚动表, 并得到:

Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: i in items, Duplicate key: string:b, Duplicate value: b

源代码是here

this 是我遵循的源代码,它可以工作

在这种情况下我需要帮助!

谢谢

【问题讨论】:

    标签: javascript angularjs


    【解决方案1】:

    您的 jsFiddle 存在一些问题。如上所述@Manjesh V,您需要添加track by $index,给您:

    <li ng-repeat="i in items track by $index">{{i.name}}</li>
    

    另外,正如@sMr 所说,您需要将$http 模块添加到指令中。

    最后,您的 jsFiddle 链接到一个非常旧的 AngularJS 版本,v1.0.0。您可以添加 1.2.1,它会工作。

    【讨论】:

      【解决方案2】:

      数组中的重复项,如果你想忽略使用track by $index

      <li ng-repeat="i in items track by $index">{{i.name}}</li>
      

      【讨论】:

        【解决方案3】:

        您似乎没有将$http 模块传递给您的主控制器。

        function Main($scope,$http) {
            $scope.items = [];
        
                $scope.loadMore = function() {
                $http.get('/echo/json').
                        success(function(data, status, headers, config) {
                            // this callback will be called asynchronously
                            // when the response is available
                            $scope.items += data;
                        }).
                        error(function(data, status, headers, config) {
                            // called asynchronously if an error occurs
                            // or server returns response with an error status.
                            console.log("call failed");
                        });
            };
            $scope.loadMore();
        } 
        

        工作demo

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-12-02
          • 2016-03-05
          • 2021-12-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多