gpt4 book ai didi

angularjs - 如果索引 % 3 == 0,则 ionic 2 新行

转载 作者:行者123 更新时间:2023-12-01 06:01:25 26 4
gpt4 key购买 nike

我有一个 ionic 网格,里面有 3 个 foreach 循环
最外层循环如下所示:

<ion-content padding>
<ion-grid>
<ion-row>
<ion-col>
<ion-row>
<ion-col *ngFor="let field1 of gs.fields; let x = index; trackBy: trackByFn">
<!-- More Foreach Loops inside each other-->
</ion-col>
</ion-row>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>


但我想每次 x%3 == 0 都得到一个新行[如果我将第一个保留在循环之外,我需要 x%3 == 0 && x != 0]
我希望保持循环内的所有内容相同,而不是复制代码
底部的屏幕

我的第一个想法是做类似的事情:

<ion-content padding>
<ion-grid>
<ion-row>
<ion-col>
<ion-row>
<ion-col *ngFor="let field1 of gs.fields; let x = index; trackBy: trackByFn">
<ion-row *ngIf="x%3==0 && x!=0">
<!-- More Foreach Loops inside each other-->
</ion-row *ngIf="x%3==0 && x!=0">
</ion-col>
</ion-row>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>


x 在 0 到 8 的范围内运行,所以 </ion-row *ngIf="x%3==0 && x!=0">因为结束标记应该没问题,因为我关闭了外部 foreach 循环之外的 ionic 行。但这不是加载。
情况如何:
How it is
我想要的样子:
How i want it to be

<ion-content padding>
<ion-grid>
<ion-row>
<ion-col *ngFor="let field1 of gs.fields; let x = index; trackBy: trackByFn">
<div *ngIf="gs.won_fields[x] == false" [ngClass]="{'bordern':x%2==0,'bordernplus1':x%2!=0}">
<ion-col *ngFor="let field2 of field1; let y = index; trackBy: trackByFn">
<ion-row>
<ion-col class="ctr fc tile" *ngFor="let tile of field2; let z = index; trackBy: trackByFn" (click)="playerClick(x,y,z)">
<span class="ctr" [ngClass]="{'player1': tile==1, 'player2' : tile==2}">{{(tile==0)? ' ': ((tile==1)? 'x' : 'o')}}</span>
</ion-col>
</ion-row>
</ion-col>
</div>
<!-- Wenn Feld gewonnen x oder o eintragen -->
<span class="ctr tile" *ngIf="gs.won_fields[x] != false" [ngClass]="{'bordern':x%2==0,'bordernplus1':x%2!=0}" [ngClass]="{'player1': gs.won_fields[x]===1, 'player2' : gs.won_fields[x]===2}">{{(gs.won_fields[x]==1)? 'x' : 'o'}}</span>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>

最佳答案

ngIf申请整体元素,而不仅仅是用于打开或关闭标签。
你可以这样做:

<ion-grid>
<ion-row>
<ion-col *ngFor="let item of items; let i = index">
<ion-row *ngIf="i%3 == 0">
{{item}}
</ion-row>
<div *ngIf="i%3 != 0">
{{item}}
</div>
</ion-col>
</ion-row>
</ion-grid>

关于angularjs - 如果索引 % 3 == 0,则 ionic 2 新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44924998/

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