如何在将NGX数据表与NGX Formly一起使用时将新行添加到模型中



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

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

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

最新更新