【发布时间】:2020-02-13 10:59:01
【问题描述】:
我希望从一个垫子表中删除一行。这是我的按钮和(点击)方法的样子:
<mat-cell *matCellDef="let element; let i = index">
<button mat-raised-button color="warn" (click)="deleteApplication(i)">
Delete
</button>
</mat-cell>
这是我的component.ts中的函数:
deleteApplication(index: number){
if (index > -1) {
let removeIndex = this.applicationData.Items;
this.applicationData.Items.splice(removeIndex[index], 1);
removeIndex = new MatTableDataSource(removeIndex);
console.log('new array:', removeIndex.filteredData);
}
}
数据源是我在 AWS 上托管的 DynamoDB 数据库中的一个数组列表。这是它的样子,在我的控制台中:
{Items: Array(8), Count: 8, ScannedCount: 8}
Count: 8
Items: Array(8)
0: {completed: false, candidate: "1", application: Array(3), timestamp: 1569837830615}
1: {completed: false, candidate: "2", application: Array(3), timestamp: 1569837830615}
2: {completed: false, candidate: "3", application: Array(3), timestamp: 1569837830615}
3: {completed: false, candidate: "4", application: Array(3), timestamp: 1569837830615}
4: {completed: false, candidate: "5", application: Array(3), timestamp: 1569837830615}
5: {completed: false, candidate: "6", application: Array(3), timestamp: 1569837830615}
6: {completed: false, candidate: "7", application: Array(3), timestamp: 1569837830615}
7: {completed: false, candidate: "8", application: Array(3), timestamp: 1569837830615}
length: 8
__proto__: Array(0)
ScannedCount: 8
__proto__: Object
我的问题是,当我点击给定行上的删除按钮时:
总是删除索引号 0,即使我点击了不在索引 0 上的行
我的视图没有渲染,即删除的行没有消失
【问题讨论】:
标签: angular typescript arraylist splice