Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度矩阵对话框不保存多个值_Javascript_Angular_Typescript_Mat Table_Mat Dialog - Fatal编程技术网

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>&nbsp;&nbsp;Ok</button> 在这里,数据对于所有记录都是通用的 上述代码仅保存第一条记录,且i=0。 如何更改saveClick()以保

我正在使用
Anular9
mat提升按钮
,如下所示:

  <button mat-raised-button (click)="saveClick()" color="primary"><mat-icon>check</mat-icon>&nbsp;&nbsp;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(...);