【发布时间】:2022-01-27 21:38:02
【问题描述】:
在我的代码中,我有一个网格,用户可以在其中输入元素。用户可以稍后编辑或删除他添加的元素。问题是,当我尝试从中间或末尾删除一个元素时,网格顶部的元素会被删除,而不是我想要的那个。这是我的代码。它有什么问题,我应该如何解决?
HTML:
<button mat-icon-button>
<mat-icon (click)="deleteWorkItem(row, i)">block</mat-icon>
</button>
TS:
dataSource: MatTableDataSource<IMaterialPlanParameter>;
deleteWorkItem(index: number) {
let tempData = this.dataSource.data.slice(0);
tempData.splice(index, 1);
this.dataSource = new MatTableDataSource(tempData);
this.EditIndex = undefined;
}
【问题讨论】:
-
你没有显示 index/i 来自哪里。总是 0 吗?
标签: javascript html angular typescript