我最终做了以下事情:
html
<ion-row *ngFor="let trio of getTriples()">
<ion-col *ngFor="let item of trio" (click)="itemTapped(item)">
<div class="row responsive-md">
<div id="icon-image-{{item.id}}"><img src="data:image/png;base64,{{item.icon}}" height="75" width="75" /></div>
<p>{{item.name}}</p>
</div>
</ion-col>
</ion-row>
打字稿
getTriples() {
let triples = [];
let length = this.subCategoryModels.length;
for (let i = 0; i < length; i += 3) {
let trio = [];
trio.push(this.subCategoryModels[i]);
if (i + 1 < length) {
trio.push(this.subCategoryModels[i + 1]);
}
if (i + 2 < length) {
trio.push(this.subCategoryModels[i + 2]);
}
triples.push(trio);
}
return triples;
}