将 ngModel 与多嵌套 JSON 对象绑定和使用
Binding and Using ngModel with Multi-nested JSON Object
我正在尝试将 ngModel 与双重嵌套的 JSON 对象绑定和使用。这就是我要使用的:(来自 PrimeNG 的日历)
<div *ngFor="let field of fields;">
<div *ngFor="let player of field.players; let i = index;">
PlayerID: {{player.playerid}}
<div *ngFor="let goal of player.goals; let j = index;">
{{goal.timestamp}} <p-calendar [showTime]="true" dateFormat="yy-mm-dd" timeFormat="hh:mm" required [(ngModel)]="field.players[i].goals[j].timestamp"></p-calendar></span><br>
</div>
</div>
</div>
但是,只有数组中的第一个日期值绑定正确,其他的根本不起作用。
也尝试为 fields
使用索引。
<div *ngFor="let field of fields; let fi = index;">
<div *ngFor="let player of field.players; let i = index;">
PlayerID: {{player.playerid}}
<div *ngFor="let goal of player.goals; let j = index;">
{{goal.timestamp}} <p-calendar [showTime]="true" dateFormat="yy-mm-dd" timeFormat="hh:mm" required [(ngModel)]="fields[fi].players[i].goals[j].timestamp"></p-calendar><br>
</div>
</div>
</div>
我正在尝试将 ngModel 与双重嵌套的 JSON 对象绑定和使用。这就是我要使用的:(来自 PrimeNG 的日历)
<div *ngFor="let field of fields;">
<div *ngFor="let player of field.players; let i = index;">
PlayerID: {{player.playerid}}
<div *ngFor="let goal of player.goals; let j = index;">
{{goal.timestamp}} <p-calendar [showTime]="true" dateFormat="yy-mm-dd" timeFormat="hh:mm" required [(ngModel)]="field.players[i].goals[j].timestamp"></p-calendar></span><br>
</div>
</div>
</div>
但是,只有数组中的第一个日期值绑定正确,其他的根本不起作用。
也尝试为 fields
使用索引。
<div *ngFor="let field of fields; let fi = index;">
<div *ngFor="let player of field.players; let i = index;">
PlayerID: {{player.playerid}}
<div *ngFor="let goal of player.goals; let j = index;">
{{goal.timestamp}} <p-calendar [showTime]="true" dateFormat="yy-mm-dd" timeFormat="hh:mm" required [(ngModel)]="fields[fi].players[i].goals[j].timestamp"></p-calendar><br>
</div>
</div>
</div>