我如何使用Angular 6 + Handsontable仅根据另一个像元值 更改一个像元值 ?

问题描述 投票:0回答:1

[当我使用afterChange挂钩(Angular 6 + Handsontable)并且在其中使用hot.getDataAtCell(...)时,行中的所有单元格都被更改

我尝试使用不同的钩子(beforeChange,afterChange),没有用的钩子

      if (changes && source) {
        this.newCellCol = source[0][0];
        this.newCellRow = source[0][1] + 1;
        this.newCellData = this.tempId.getDataAtCell(source[0][0], source[0][1]);
        console.log(this.newCellData);
      }
    },
    afterChange: (changes, source) => {
      if (changes && source) {
        this.tempId.setDataAtCell(this.newCellCol, this.newCellRow, this.newCellData);
      }
    }
  };

我想也将值添加到它旁边的单元格中但它被添加到同一行的所有单元格中最终解决方案是基于一个单元格中输入的数据,将不同的计算数据插入同一行中的3个不同的单元格中]

[当我使用afterChange挂钩(Angular 6 + Handsontable)并且在其中使用hot.getDataAtCell(...)时,行中的所有单元格都被更改,我尝试使用不同的挂钩(beforeChange,afterChange),非...] >

angular6 cell handsontable
1个回答
0
投票

在afterChange钩子的changes数组中,您可以访问行,prop(列),oldValue和newValue。您可以通过上述内容监听确切列中的更改,还可以创建一个将被调用的自定义方法,该方法将基于上述内容触发更改到您的目标单元格。

 afterChanges: (changes, source) => {
     //iterate through changes
     row = changes[iterator][0]
     col = changes[iterator][1]
     oldValue = changes[iterator][2]
     newValue = changes[iterator][3]

     //listen for changes in the desired columns
     //invoke the custom method or add a block to set Data for the target cell(s)
 }
© www.soinside.com 2019 - 2024. All rights reserved.