我正在使用SyncFusion Grid
并且我valueAccessor
为特定列定义了如下:
export interface GridColumn<idT> {
...
valueAccessor?: (
field: string,
data: GridData<idT>,
column: Column
) => ValueAccessor | string;
}
这是列定义:
{
field: 'decimalCount',
headerText: 'Decimals',
textAlign: GridTextAlign.Center,
headerTextAlign: GridTextAlign.Center,
width: 50,
editType: GridEditType.NumericTextBox,
valueAccessor: (
field: string,
data: Partial<CustomDataGridData>
): string => data[field] ?? 'N/A',
}
但我收到以下错误
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Partial<CustomDataGridData>'.
No index signature with a parameter of type 'string' was found on type 'Partial<CustomDataGridData>'.
在html
文件valueAccessor
中应用如下:
<e-column
...
[valueAccessor]="column.valueAccessor ?? null"
>
我已经设法通过将data
对象转换为any
=>来解决这个问题,(data as any)[field] ?? 'N/A'
并且任何事情都按预期工作,但我无法理解原因。