aggrid valueGetter/valueSetter 超出组件范围

aggrid valueGetter/valueSetter out of components scope

我正在使用 ag-grid 来显示和编辑一些后端数据。 因为值存储为枚举,所以我想将枚举数转换为漂亮的显示文本,并使选项在 select 元素上可用。

为此,我使用以下列 def:

columnDefs = [
   {    
      valueGetter: this.stringifyType,
      valueSetter: this.setType,
      colId: 'typCol',
      headerName: 'Type',
      editable: true,
      cellEditor: 'agSelectCellEditor',
      cellEditorParams: { values: this.arrTypMapping },
  }

如果我没猜错,agSelectCellEditor 只接受一个字符串数组作为值。为了完成这项工作,我创建了 valueGetter 和 valueSetter 函数。它将数据库整数值转换为漂亮的显示文本并反转。到目前为止效果很好。

这是我的问题,在 getter / setter 函数中我无法访问 angular 组件的任何对象。显然,aggrid 在组件范围之外运行这些功能。 是否可以通过某种方式访问​​那些 getter/setter 函数中我的组件的对象?

感谢您的帮助!

里克

Aggrid 允许将一些上下文传递给配置对象,稍后您可以在单元格中使用它。简单demo! :)