mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 02:59:58 +08:00
parent
35a9d94c92
commit
9a67f3571d
@ -162,7 +162,7 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
|
||||
const { childrenColumnName = 'children' } = mergedExpandable;
|
||||
|
||||
const expandType: ExpandType = React.useMemo<ExpandType>(() => {
|
||||
if (rawData.some(item => (item as any)[childrenColumnName])) {
|
||||
if (rawData.some(item => (item as any)?.[childrenColumnName])) {
|
||||
return 'nest';
|
||||
}
|
||||
|
||||
@ -183,7 +183,7 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
|
||||
return rowKey;
|
||||
}
|
||||
|
||||
return (record: RecordType) => (record as any)[rowKey as string];
|
||||
return (record: RecordType) => (record as any)?.[rowKey as string];
|
||||
}, [rowKey]);
|
||||
|
||||
const [getRecordByKey] = useLazyKVMap(rawData, childrenColumnName, getRowKey);
|
||||
|
@ -160,6 +160,19 @@ describe('Table', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should not crash when dataSource is array with none-object items', () => {
|
||||
mount(
|
||||
<Table
|
||||
columns={[
|
||||
{
|
||||
title: 'name',
|
||||
},
|
||||
]}
|
||||
dataSource={['1', 2, undefined, {}, null, true, false, 0]}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
|
||||
it('prevent touch event', () => {
|
||||
const wrapper = mount(
|
||||
<Table
|
||||
|
@ -30,7 +30,7 @@ export default function useLazyKVMap<RecordType>(
|
||||
const rowKey = getRowKey(record, index);
|
||||
kvMap.set(rowKey, record);
|
||||
|
||||
if (childrenColumnName in record) {
|
||||
if (record && typeof record === 'object' && childrenColumnName in record) {
|
||||
dig((record as any)[childrenColumnName] || []);
|
||||
}
|
||||
});
|
||||
|
@ -59,7 +59,7 @@ function flattenData<RecordType>(
|
||||
(data || []).forEach(record => {
|
||||
list.push(record);
|
||||
|
||||
if (childrenColumnName in record) {
|
||||
if (record && typeof record === 'object' && childrenColumnName in record) {
|
||||
list = [
|
||||
...list,
|
||||
...flattenData<RecordType>((record as any)[childrenColumnName], childrenColumnName),
|
||||
|
Loading…
Reference in New Issue
Block a user