【问题标题】:Type has no properties in common with type 'ColumnType<any>'类型与类型 'ColumnType<any>' 没有共同的属性
【发布时间】:2022-01-03 14:30:59
【问题描述】:

我正在编写一个带有 react 和 ant design 的应用程序

我要使用antd表

但它没有显示我的数据

代码

const ListOfProperties = () => {
  const columns = [
    {
      type: "Type",
      state: "State",
      location: "Location",
    },
  ];
  const properties = [
    {
      type: "Flat",
      state: "Anambra",
      location: "Udoka",
    },
    {
      type: "Flat",
      state: "Anambra",
      location: "Udoka",
    },
  ];
  return (
    <Skeleton active loading={loading}>
      <Table columns={columns} dataSource={properties} />
    </Skeleton>
  );
};

export default ListOfProperties;

我创建了一个对象数组,我将它们传递给数据源并将列传递给列

如文档中所述

但我遇到了错误

错误

Type '{ type: string; state: string; location: string; }' has no properties in common with type 'ColumnType&lt;any&gt;'.

【问题讨论】:

    标签: reactjs typescript antd


    【解决方案1】:

    您需要提供titledataIndexkey。请务必先在documentation 中查找。

    const columns = [
      {
        title: "Type",
        dataIndex: "type",
        key: "type"
      },
      {
        title: "State",
        dataIndex: "state",
        key: "state"
      },
        {
        title: "Location",
        dataIndex: "location",
        key: "location"
      },
     ];
    

    【讨论】:

      猜你喜欢
      • 2023-01-05
      • 2017-11-27
      • 1970-01-01
      • 1970-01-01
      • 2023-01-11
      • 2022-08-17
      • 2022-08-10
      • 2020-06-14
      相关资源
      最近更新 更多