如何在Angular中移除索引

14 浏览
0 Comments

如何在Angular中移除索引

如何按照索引值进行删除,我有一个参数和删除按钮,我尝试将我的参数放到删除按钮中,但它不起作用,如何修复?

deleteRowFiles(rowIndex: number){
  this.getListFileName();
  if(this.uploadAttachments.length > 1){
    Swal.fire({
      title: 'Are you sure?',
      text: 'You will not be able to recover this data!',
      icon: 'error',
      showCancelButton: true,
      confirmButtonText: 'Confirm',
      cancelButtonText: 'Cancel'
    }).then((result) => {
      if(result.value){
        this.uploadAttachments.removeAt(rowIndex);
        this.microSvc.deleteFile(this.iData.transactionType,this.uploadedFiles).pipe(
         return this.refreshPage();
        }) 
      }else if (result.dismiss === Swal.DismissReason.cancel){}
    })
  }

HTML


 

admin 更改状态以发布 2023年5月21日
0
0 Comments

我通常会用一个已经过滤掉要删除项的新数组来替换数组引用

this.uploadAttachments = this.uploadAttachments.filter((_, i) => i !== rowIndex);

0
0 Comments

JavaScript中没有removeAt功能,可以使用splice代替

 this.uploadAttachments.splice(rowIndex,1);

0