错误:[ngRepeat:dupes]是什么意思? [英] Error: [ngRepeat:dupes] what does this mean?

查看:205
本文介绍了错误:[ngRepeat:dupes]是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

repeat指令从api输出葡萄酒记录.我有一个工厂函数来提供wine API,然后可以在我的控制器中访问

repeat directive outputing wine records from an api. I have a factory function to serve up the wine API which is then accessed in my controller

app.factory("Wine", function ($http){
     var factory = {};

     //getWines 
     factory.getWines = function(){ 
      return $http.get("http://www.greatwines.9000.com")
     }

}

控制器:

    app.controller("winesCtrl", function($scope, $http, Wine){
        Wine.getWines()
         .success(function(wines){
           $scope.wines = wines;
        })
        .error(function(){
             alert("Error!");
         });
    });

VIEW:

<h2>Wine list</h2>
    <div class="row margin-top-20 wine-container" ng-repeat="wine in wines">
        <div class="col-sm-3">
            <img src="{{wine.picture}}" class="img-responsive" />
        </div>
        <div class="col-sm-9">
            <div class="margin-top-20">
                <span class="bold">Name: </span><span>{{wine.name}}</span>
            </div>
            <div>
                <span class="bold">Year: </span><span>{{wine.year}}</span>
            </div>
            <div>
                <span class="bold">Grapes: </span><span>{{wine.grapes}}</span>
            </div>
            <div>
                <span class="bold">Country: </span><span>{{wine.country}}</span>
            </div>
            <div>
                <span class="bold">Region: </span><span>{{wine.region}}</span>
            </div>
            <div>
                <span class="bold">Price: </span><span>{{wine.price}}</span>
            </div>
            <div>
                <span class="bold">{{wine.description}}</span>
            </div>
            <div class="margin-top-20">
                <a href="#/wines/{{wine.id}}" class="btn btn-default">Edit Wine</a>
            </div>
        </div>
    </div>

我点击了这个错误,并以典型的模糊" angularjs方式得到了这个信息:

I clicked on this error and in typical "vague" angularjs fashion I get this:

Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: wine in wines, Duplicate key: string:e, Duplicate value: e

这是什么意思?葡萄酒与葡萄酒"不同,为什么会认为它是重复的?

What does this mean? wine is not the same as "wines" so why does it think it is a duplicate?

推荐答案

在ngRepeat表达式中存在重复的键时发生.重复键被禁止,因为AngularJS使用键将DOM节点与项目相关联.

Occurs if there are duplicate keys in an ngRepeat expression. Duplicate keys are banned because AngularJS uses keys to associate DOM nodes with items.

这意味着$ scope.wines具有一些重复的值.

This means that $scope.wines have some values which are duplicate.

您也可以参考此帖子:角度ng-repeat错误不允许在转发器中重复".

You can also refer this post : Angular ng-repeat Error "Duplicates in a repeater are not allowed."

这篇关于错误:[ngRepeat:dupes]是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆