gpt4 book ai didi

duplicates - 错误 : [ngRepeat:dupes] what does this mean?

转载 作者:行者123 更新时间:2023-12-03 14:39:52 24 4
gpt4 key购买 nike

重复指令从 api 输出葡萄酒记录。我有一个工厂函数来提供 wine API,然后在我的 Controller 中访问

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

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

}

Controller :
    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 方式得到了这个:
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

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

最佳答案

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

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

你也可以引用这个帖子:Angular ng-repeat Error "Duplicates in a repeater are not allowed."

关于duplicates - 错误 : [ngRepeat:dupes] what does this mean?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33018200/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com