From 448a4c2809672480f8f635d7cc4661554112598a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E6=9C=A8?= Date: Tue, 8 Jun 2021 11:19:11 +0800 Subject: [PATCH] feat(table): updateTableDataRecord support functional rowKey --- src/components/Table/src/hooks/useDataSource.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/Table/src/hooks/useDataSource.ts b/src/components/Table/src/hooks/useDataSource.ts index 6dfd15cf0..d3bfa3db3 100644 --- a/src/components/Table/src/hooks/useDataSource.ts +++ b/src/components/Table/src/hooks/useDataSource.ts @@ -155,12 +155,16 @@ export function useDataSource( ): Recordable | undefined { if (!dataSourceRef.value || dataSourceRef.value.length == 0) return; const rowKeyName = unref(getRowKey); - if (typeof rowKeyName !== 'string') { + if (!rowKeyName) { return; } - const row = dataSourceRef.value.find( - (r) => Reflect.has(r, rowKeyName as string) && r[rowKeyName as string] === rowKey - ); + const row = dataSourceRef.value.find((r) => { + if (typeof rowKeyName === 'function') { + return (rowKeyName(r) as string) === rowKey; + } else { + return Reflect.has(r, rowKeyName) && r[rowKeyName] === rowKey; + } + }); if (row) { for (const field in row) { if (Reflect.has(record, field)) row[field] = record[field];