Ant design Table组件报错TypeError: Object(...) is not a function

user_tYDk6iCh
  • 63

rowSelection是Table组件的一个配置项,参考https://ant.design/components...

代码主要部分如下述所示,其中const diffKeys = selected报错TypeError: Object(...) is not a function,如图一所示

            const rowSelection = {
                getCheckboxProps: (item: any) => ({ disabled: itemDisabled }), 
                onSelectAll(selected: boolean, selectedRows: any[]) {   
                    const treeSelectedKeys = selectedRows
                        .filter((item: any) => !item.disabled)  
                        .map(({ key }) => key);
                        console.log(treeSelectedKeys);  
                    const diffKeys = selected            //此行报错!
                        ? difference(treeSelectedKeys)
                        : difference(listSelectedKeys);
                    onItemSelectAll(diffKeys, selected);
                    console.log(diffKeys);
                },
                onSelect({ key }:any, selected:boolean) {          
                    onItemSelect(key, selected);
                },
                selectedRowKeys: listSelectedKeys,
            };
            
            return (
                <Table
                    rowSelection={rowSelection}
                    columns={columns}
                    dataSource={filteredItems}
                    onRow={({ key, disabled: itemDisabled }:any) => ({
                        onClick: () => {
                            if (itemDisabled || listDisabled) return;
                            onItemSelect(key, !listSelectedKeys.includes(key));
                        },
                    })}
                />
            );

image.png

onSelectAllChange的报错代码定位如图二所示
image.png

当在表格中点击全选时就会报错,不知道问题出在哪里,github上proTable组件有个相似的报错说是重新安装依赖就可以了,但是当前这个更新了依赖版本依然不行,请问有什么解决办法吗?

回复
阅读 1.3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
你知道吗?

宣传栏