0

使用 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

4

1 回答 1

0

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 };

这将在我的表中添加一个新行,并正确绑定它。

于 2020-07-16T11:50:30.957 回答