如何获得蚂蚁设计表中的行索引?

时间:2020-10-31 15:54:44

标签: reactjs react-native ant-design-pro

我想在ant设计表中显示行的索引。例如:我得到10行数据时为1到10。

const columns = [{
    title: 'ID',
    dataIndex: 'id',
    key: 'id',
    width: '5%'
  },
...
];
<Table key="table" columns={columns} dataSource={listData} pagination= {false} />

1 个答案:

答案 0 :(得分:0)

您的要求不清楚。更好地向我们展示您想要实现的输出。如果您需要获取“列”数组中对象的索引,则可以使用迭代器来获取它。

例如-1:

columns.map((column, index) => {
  // Your statements will go here
})

例如-2:

columns.forEach((column, index) => {
  // Your statements will go here
})

实时示例:

<Table key="table" columns={columns} dataSource={listData} pagination= {false} >
  <tbody>
    {columns.map((column, index) => {
      return (
        <row>
          <td>{index}</td>
        </row>
      )}
    }
  </tbody>
</Table>

还有其他迭代器,例如“ lodash”,“ forEach”。这可能是您开始学习迭代器https://www.w3schools.com/js/js_array_iteration.asp