我定义了一个自定义过滤器,如下所示:

<div class="idea item" ng-repeat="item in items" isoatom>    
    <div class="section comment clearfix" ng-repeat="comment in item.comments | range:1:2">
        ....
    </div>
</div>

正如您所看到的,使用过滤器的ng-repeat嵌套在另一个ng-repeat中

过滤器的定义如下:

myapp.filter('range', function() {
    return function(input, min, max) {
        min = parseInt(min); //Make string input int
        max = parseInt(max);
        for (var i=min; i<max; i++)
            input.push(i);
        return input;
    };
});

我得到:

错误:在中继器中不允许重复。Repeater: comment in item.comments | range:1:2 ngRepeatAction@https://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/an


当前回答

如果在使用SharePoint 2010时偶然发生这个错误:重命名你的.json文件扩展名,并确保更新你的restService路径。不需要额外的“按$index跟踪”。

幸运的是,我转发了这个链接到这个基本原理:

.json在SP2010中成为一种重要的文件类型。SP2010包含了一些web服务端点。这些文件的位置是14hive\isapi文件夹。这些文件的扩展名是.json。这就是它给出这样一个错误的原因。 “只关心json文件的内容是json -而不是它的文件扩展名”

一旦文件扩展名被改变,就应该全部设置好。

其他回答

中继器中不允许重复。使用'track by'表达式指定唯一的键。

Repeater: {0}, Duplicate key: {1}, Duplicate value: {2}

例子

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="angular.js"></script>

</head>
<body>
    <div ng-app="myApp" ng-controller="personController">
        <table>
            <tr> <th>First Name</th> <th>Last Name</th> </tr>
            <tr ng-repeat="person in people track by $index">
                <td>{{person.firstName}}</td>
                <td>{{person.lastName}}</td>
                <td><input type="button" value="Select" ng-click="showDetails($index)" /></td>
            </tr>

        </table> <hr />
        <table>
            <tr ng-repeat="person1 in items track by $index">
                <td>{{person1.firstName}}</td>
                <td>{{person1.lastName}}</td>
            </tr>
        </table>
        <span>   {{sayHello()}}</span>
    </div>
    <script> var myApp = angular.module("myApp", []);
        myApp.controller("personController", ['$scope', function ($scope)
        { 
            $scope.people = [{ firstName: "F1", lastName: "L1" },
                { firstName: "F2", lastName: "L2" }, 
                { firstName: "F3", lastName: "L3" }, 
                { firstName: "F4", lastName: "L4" }, 
                { firstName: "F5", lastName: "L5" }]
            $scope.items = [];
            $scope.selectedPerson = $scope.people[0];
            $scope.showDetails = function (ind) 
            { 
                $scope.selectedPerson = $scope.people[ind];
                $scope.items.push($scope.selectedPerson);
            }
            $scope.sayHello = function ()
            {
                return $scope.items.firstName;
            }
        }]) </script>
</body>
</html>

我的JSON回复是这样的:

{
    "items":  [
        {
            "index": 1, "name": "Samantha", "rarity": "Scarborough","email": "maureen@sykes.mk"
        },{ 
            "index": 2, "name": "Amanda", "rarity": "Vick", "email": "jessica@livingston.mv"
        }
    ]
}

因此,我在变量中使用ng-repeat = "item。项目”来展示它。

为了防止这种情况发生在其他人身上,我在这里记录了这一点,我得到这个错误是因为我错误地将ng-model设置为ng-repeat数组:

 <select ng-model="list_views">
     <option ng-selected="{{view == config.list_view}}"
         ng-repeat="view in list_views"
         value="{{view}}">
         {{view}}
     </option>
 </select>

而不是:

<select ng-model="config.list_view">
     <option ng-selected="{{view == config.list_view}}"
         ng-repeat="view in list_views"
         value="{{view}}">
         {{view}}
     </option>
 </select>

我检查了数组,没有任何重复,只是再次检查你的变量。

如果在< ul>标记中调用ng-repeat,则可以允许重复。参考这个链接。 看到Todo2.html

你想让你的“range”过滤器做什么?

以下是我认为您正在尝试做的工作示例:http://jsfiddle.net/evictor/hz4Ep/

HTML:

<div ng-app="manyminds" ng-controller="MainCtrl">
  <div class="idea item" ng-repeat="item in items" isoatom>    
    Item {{$index}}
    <div class="section comment clearfix" ng-repeat="comment in item.comments | range:1:2">
      Comment {{$index}}
      {{comment}}
    </div>
  </div>
</div>

JS:

angular.module('manyminds', [], function() {}).filter('range', function() {
    return function(input, min, max) {
        var range = [];
        min = parseInt(min); //Make string input int
        max = parseInt(max);
        for (var i=min; i<=max; i++)
            input[i] && range.push(input[i]);
        return range;
    };
});

function MainCtrl($scope)
{
    $scope.items = [
        {
            comments: [
                'comment 0 in item 0',
                'comment 1 in item 0'
            ]
        },
        {
            comments: [
                'comment 0 in item 1',
                'comment 1 in item 1',
                'comment 2 in item 1',
                'comment 3 in item 1'
            ]
        }
    ];
}