【问题标题】:How add new rows to model when using NGX-DataTable with NGX-Formly将 NGX-DataTable 与 NGX-Formly 一起使用时如何向模型添加新行
【发布时间】:2020-07-16 19:50:30
【问题描述】:

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

【问题讨论】:

    标签: angular ngx-datatable ngx-formly


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 2020-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多