使用Formly,我实现了一个类似于这里找到的解决方案:https://formly.dev/examples/advanced/datatable-integration
这适用于显示现有数据,当尝试添加新行时会出现此问题。我需要一种方法来更新FormGroup列表,我目前已经通过再次添加第一行来欺骗它。从视觉上看,它看起来是正确的,但它总是绑定到错误的行。
var newRow = this.fields[1].fieldGroup[0];
this.fields[1].fieldGroup.push(newRow);我在这里有一个例子(上面例子的修改版本):https://stackblitz.com/edit/formly-add-ngxdatatablerow?file=src%2Fapp%2Fapp.component.ts
发布于 2020-07-16 19:50:31
Abdellatif Ait boudad给我指出了这个链接,它解决了我的问题:https://github.com/ngx-formly/ngx-formly/issues/2250#issuecomment-630577383
除了推送到数组之外,我还设置了模型,以便Formly能够检测到更改。
this.model.investments.push({});
this.model = { ...this.model, investments: this.model.investments };这将向我的表中添加一个新行,并正确地绑定它。
https://stackoverflow.com/questions/62830478
复制相似问题