首页 > 解决方案 > 如何在保存到数据库之前编辑新添加对象的保存数据

问题描述

我有一个formarray,如果我编辑来自数据库中保存的数据的值,因为它的唯一ID为agentW9id,因此它会在该特定行中更新,但对于新添加的行,因为没有唯一ID ,如何在编辑时保存对该特定行的更改并在单击保存按钮时显示更改的值。

我在这里有工作演示: DEMO

TS:

saveW9Details(item) {

        if(this.employee ) {
          if(item.agentW9id.value) {
            for(var i=0;i<this.employee.length;i++){
              if(this.employee[i].agentW9id===item.agentW9id.value){
                this.employee[i].taxId=item.taxId.value;
                this.employee[i].businessType=item.businessType.value;
                this.employee[i].signatureDate=item.signatureDate.value;
                this.employee[i].agentW9id = item.agentW9id.value;
                // updated=true;
                this.temporaryControls.push(this.employee[i])
              }
           }
          } else {

            var temp={
              taxId:item.taxId.value,
              signatureDate:item.signatureDate.value,
              businessType: item.businessType.value,
              agentW9id:item.agentW9id.value,
              businessName: item.businessName[0].value,
             originalFileName:item.fileName.value?item.fileName.value.slice(12):''
            }
            if(this.employee) {
              this.employee.push(temp);
              this.temporaryControls.push(temp)
            } 
      //  this.getFormData.removeAt(item)
          }
        } else {
         console.log(item,"dsds")

            let temp={
              taxId:item.taxId.value,
              signatureDate:item.signatureDate.value,
              businessType: item.businessType.value,
              agentW9id:item.agentW9id.value,
              businessName: item.businessName[0].value,
             originalFileName:item.fileName.value?item.fileName.value.slice(12):''
            };
            this.temporaryControls.push(temp)
        }

       this.getFormData.removeAt(item);


        }

}

标签: angularangular-reactive-forms

解决方案


推荐阅读