我努力在我的控制器中分块输出一些数据,然后在我的视图中正确输出。
我有(例如)50组信息。
1. name: Chris
rank: 1
location: Australia
2. name: Sarah
rank: 13
location: UK
等等。
我像这样分块:
function chunk(arr, size) {
var newArr = [];
for (var i=0; i<arr.length; i+=size) {
newArr.push(arr.slice(i, i+size));
}
return newArr;
}
所以:
$ scope.information = chunk(information,4);
我有一个<div class="row">
,然后有4个column divs within that
,我希望显示所有信息,将其分成每行4列。
我正在尝试这样做:
<div class="row services" ng-repeat="rows in information">
<div class="col-md-3 col-sm-6 item scrollimation fade-up" ng-repeat="item in rows">
<h2>{{ item }}</h2>
</div>
</div>
它似乎无法奏效。
我是AngJS的新手。任何帮助将不胜感激。
谢谢!
编辑:信息数组的console.log。 这基本上就是它的样子。有点不同的架构,但它的想法相同。
Array[1]0: Array[3]0: Object$$hashKey: "object:6"datetime: "14/01/2015"id: "dc995b0f486868a4"location: "Australia"rank: "Legendary Eagle Master"steamname: "KriiV"__proto__: Object1: Object$$hashKey: "object:7"datetime: "2015-02-19T11:20:06.427Z"id: "cbd1cbb908a9a9c3"location: "Australia"rank: "Silver III"steamname: "http://steamcommunity.com/id/asdf"__proto__: Object2: Object$$hashKey: "object:8"datetime: "2015-02-19T11:25:55.099Z"id: "7796ac966f129897"location: "United Kingdom"rank: "Silver IV"steamname: "http://steamcommunity.com/id/asdfasd"__proto__: Objectlength: 3__proto__: Array[0]length: 1__proto__: Array[0]