【React】antd在table中使用dropdown组件

官方给出的dropdwpn使用方法无法在table中得到每一行的信息

import { Menu, Dropdown, Icon } from 'antd';

const menu = (
  <Menu>
    <Menu.Item>
      <a target="_blank" rel="noopener noreferrer" href="http://www.alipay.com/">
        1st menu item
      </a>
    </Menu.Item>
    <Menu.Item>
      <a target="_blank" rel="noopener noreferrer" href="http://www.taobao.com/">
        2nd menu item
      </a>
    </Menu.Item>
    <Menu.Item>
      <a target="_blank" rel="noopener noreferrer" href="http://www.tmall.com/">
        3rd menu item
      </a>
    </Menu.Item>
  </Menu>
);

ReactDOM.render(
  <Dropdown overlay={menu}>
    <a className="ant-dropdown-link" href="#">
      Hover me <Icon type="down&
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
如果您需要在 Ant Design 的 Table 组件嵌套 Table 组件,可以使用 `expandedRowRender` 属性来实现。下面是一个示例代码: ```jsx import React from 'react'; import { Table } from 'antd'; const columns = [ { title: 'Name', dataIndex: 'name' }, { title: 'Age', dataIndex: 'age' }, { title: 'Address', dataIndex: 'address' }, ]; const data = [ { key: 1, name: 'John Brown', age: 32, address: 'New York No. 1 Lake Park', children: [ { key: 11, name: 'Jim Green', age: 42, address: 'London No. 2 Lake Park', }, { key: 12, name: 'Joe Black', age: 32, address: 'Sidney No. 3 Lake Park', }, ], }, { key: 2, name: 'Jim Green', age: 42, address: 'London No. 2 Lake Park', children: [ { key: 21, name: 'John Brown', age: 32, address: 'New York No. 1 Lake Park', }, { key: 22, name: 'Joe Black', age: 32, address: 'Sidney No. 3 Lake Park', }, ], }, { key: 3, name: 'Joe Black', age: 32, address: 'Sidney No. 3 Lake Park', children: [ { key: 31, name: 'John Brown', age: 32, address: 'New York No. 1 Lake Park', }, { key: 32, name: 'Jim Green', age: 42, address: 'London No. 2 Lake Park', }, ], }, ]; const App = () => { const expandedRowRender = (record) => { const columns = [ { title: 'Name', dataIndex: 'name' }, { title: 'Age', dataIndex: 'age' }, { title: 'Address', dataIndex: 'address' }, ]; const data = record.children; return <Table columns={columns} dataSource={data} pagination={false} />; }; return <Table columns={columns} dataSource={data} expandable={{ expandedRowRender }} />; }; export default App; ``` 在这个示例代码,我们定义了一个 `expandedRowRender` 函数,在这个函数,我们使用 Table 组件来渲染子表格。然后,在主表格,我们将 `expandedRowRender` 函数传递给 `expandable` 属性来实现嵌套表格的效果。具体地,当用户点击主表格的一个行时,它的子表格就会被展开。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值