Javascript 角度矩阵对话框不保存多个值
我正在使用Javascript 角度矩阵对话框不保存多个值,javascript,angular,typescript,mat-table,mat-dialog,Javascript,Angular,Typescript,Mat Table,Mat Dialog,我正在使用Anular9和mat提升按钮,如下所示: <button mat-raised-button (click)="saveClick()" color="primary"><mat-icon>check</mat-icon> Ok</button> 在这里,数据对于所有记录都是通用的 上述代码仅保存第一条记录,且i=0。 如何更改saveClick()以保
Anular9
和mat提升按钮
,如下所示:
<button mat-raised-button (click)="saveClick()" color="primary"><mat-icon>check</mat-icon> Ok</button>
在这里,数据
对于所有记录都是通用的
上述代码仅保存第一条记录,且i=0
。
如何更改saveClick()
以保存所有记录,直到i
?H
不要使用for循环,而是尝试使用map,一旦您拥有了saudit数组,然后将其作为参数调用您的服务
顺便说一句,将您的呼叫转移到环路/映射之外的服务
**编辑
我不清楚您的业务逻辑,但我至少会将该映射用作标准点
// Map each Id in the hostid array to SInterface
const saudits: SInterface = this.hostid.map((id, index) => {
return {
data: this.data,
eid: this.eid[index],
serverId: id,
} as SInterface;
});
// Pass all saudits at once to service
this.sservice.addRecord(saudits).subscribe(...);
您能告诉我使用
map
更新后的代码是什么样子吗?
// Map each Id in the hostid array to SInterface
const saudits: SInterface = this.hostid.map((id, index) => {
return {
data: this.data,
eid: this.eid[index],
serverId: id,
} as SInterface;
});
// Pass all saudits at once to service
this.sservice.addRecord(saudits).subscribe(...);