javascript - 无法将数据推送到 FormArray 中的 mat-table 并且该表单处于循环中所以我有多个表单每个表单都有一个 mat-table
问题描述
当我试图推送数据以形成它不更新到该表单数组时,它总是以第一个表单数组更新,
export class Sample {
assetsAndGiftsForm: FormGroup;
constructor(private _fb: FormBuilder) {
}
public initAssetsForm() {
this.assetsAndGiftsForm = this._fb.group({
borrowers: this._fb.array([this.sample()]),
})
}
public sample() {
let reo:ReoDto[]=[]
return this._fb.group({
assets: this._fb.array([]),
gifts: this._fb.array([]),
reo: [[]]
})
}
}
模板
<table mat-table #matTable [dataSource]="this.assetsAndGiftsForm.value.borrowers[borrowerIndex].reo">
将数据添加到表单后,我尝试将数据推送到 Mat-table 但仅在第一个表中更新
@ViewChild(MatTable) matTable: MatTable<any>;
onSaveReo() {
let control = this.getBorrowerControl.at(this.curreentBorrowerIndex.value).get('reo') as FormArray;
control.value.push(this.reoForm.value);
this.matTable.dataSource = this.getBorrowerControl.at(this.curreentBorrowerIndex.value).get('reo').value;
// @error :: after adding new 'reo' into any one of borrowers, its pushing to only first table ,
//datasurce is not varying
this.assetsAndGiftsForm.updateValueAndValidity()
this.matTable.renderRows();
this.addPropertyPopupClose();
}
解决方案
推荐阅读
- python - 以最低要求导出 Conda 环境
- c++ - 使用 getline() 时 while 和 if 的区别
- c - 在 c 中,当我在条件语句中分配一个字符串时,它有错误
- google-forms - 当我尝试打开受限的 Google 表单时如何更改帐户?
- r - 尝试在 R 中进行左连接合并,但想要选择特定的列。接收错误信息
- python - 如何在python中使用pandas将数据设置为csv文件
- swiftui - 如何获取 SwiftUI View 的当前颜色?
- opencart - 电子邮件订单 opencart 中的库存状态
- python - Python pandas在另一列的元素列表中查找一列的元素
- angular - 如何在 spec.test 文件中定义“component.QRcode”