ng多次重复追加数据
ng-repeat appending data multiple times
HTML
<div ng-app="templeApp" ng-controller="templeList">
<div ng-repeat="temple in temples track by $index" >
<h2>{{temple.strTempleName}}</h2>
<h4>{{temple.strTempleDescription}}</h4>
<h4>5km from current location</h4>
</div>
</div>
JS
var templeApp = angular.module('templeApp', [])
.controller('templeList',function($scope,$http){
$scope.temples = [{"_id":"new","strTempleName":"Temple 1 Name","strTempleDescription":"Temple 1 description","strContactNumber":"+91899999999","strTempleLocation":"Chennai","iTempleRating":5,"strContactPersonName":"","strTempleCoordinates":""}] ;
$http.get("https://gist.githubusercontent.com/vigneshvdm/d106ea482a792c60dff8/raw/c8f020eb54c4068e40884b8d84c972d92e8e4e08/vicky%20test%20file").success(function(data){
$scope.temples = data[0]; //uncomment this line to see error
console.log(data[0]);
});
});
问题
当我注释$scope.temples = data[0];
行时,ne repeat只追加数据一次,但当我将数据分配给$scope.temps时,它多次追加相同的数据
演示链接
删除ng repeat中的track by $index
,并像下面的一样更改
在这个例子中,我使用了temple.strTempleName作为track-by-filter,确保它返回唯一的名称。
<div ng-app="templeApp" ng-controller="templeList">
<div ng-repeat="temple in temples track by temple.strTempleName" >
<h2>{{temple.strTempleName}}</h2>
<h4>{{temple.strTempleDescription}}</h4>
<h4>5km from current location</h4>
</div>
</div>
相关文章:
- jQuery动态使用.append()添加输入,但发布表单不是追加数据
- 从脚本后加载的处理程序追加数据
- 如何在单击事件中追加数据来自数据表
- jQuery InfiniteScroll如何追加数据
- D3 表根据不同的数据类型追加数据
- jQuery.移动子追加数据
- 使用纯 Javascript 在类中追加数据
- 单击时从 AJAX .each() 循环追加数据
- 如何等到添加表单数据后再追加数据
- 如何在追加数据并完成该数据的函数后连续运行函数
- jQuery - 如何向下滑动正文追加数据
- Onchange使用ajax在表行中追加数据
- 自动求和和和追加数据javascript
- 追加数据属性时出现无法识别的表达式
- 可处理的无限滚动追加数据和应用合并单元格格式
- 使用jQuery隐藏和追加数据
- 为什么弹出窗口不能'工作时追加数据到主体表
- 在另一个文件中追加数据
- 向Google地图的业务位置追加数据
- 如何选择在哪里追加数据