【发布时间】:2017-03-22 04:47:23
【问题描述】:
我需要关于在 ng-repeat 中订购 JSON 的帮助。我想按 item.id 排序我的数据(从最高到最低)。我尝试了许多互联网上的提示,但也许我只是做错了什么,因为它们都不适合我......我的代码:
$http.get('http://jastrzebieonline.pl/drogi/data/najnowsze.php')
.success(function(res){
$scope.news = res;
console.log("Ok");
})
.error(function(data, status) {
console.log("Error");
})
<div ng-repeat="item in news">
<a href="{{ item.id }}">
<img src="{{ item.image }}">
<h2>{{ item.title }}</h2>
<p>{{ item.date }}</p>
<p>{{ item.text }}</p>
</div>
</a>
</div>
【问题讨论】:
-
确保你的 'id' 属性是整数类型。然后就做
ng-repeat="item in news | orderBy:'-id'"
标签: angularjs json ionic-framework ng-repeat