简体   繁体   English

反应 Typescript: Ant 设计表与下拉列传递记录到 function

[英]React Typescript: Ant Design Table with Dropdown Column pass Record to function

Following Column :Column

{ title: "Action", render: (record: ToDoClass) => {
   return (
      <Dropdown overlay={menu}>
         <Button>
            User <DownOutlined />
         </Button>
      </Dropdown>
   )
}},

has the menu :menu

const menu = (
   <Menu onClick={() => this._updateUser}>
      <Menu.Item key="0" />
      <Menu.Item key="1">User 1</Menu.Item>
      <Menu.Item key="2">User 2</Menu.Item>
   </Menu>
);

must call the function: this._updateUser with the parameter record from the column and key from the menu :必须使用column中的参数recordmenu中的key调用function: this._updateUser

private _updateUser = (record: ToDoClass, key: any): void => {
   console.log(record, key); //<- Console shows nothing
}

在此处输入图像描述

Based on the documentation , the onClick prop takes a function that takes an object { item, key, keyPath, domEvent } .根据文档onClick prop 采用 function 采用 object { item, key, keyPath, domEvent } You can try changing your _updateUser and menu to something like this:您可以尝试将_updateUsermenu更改为以下内容:

<Menu onClick={this._updateUser}>
...
private _updateUser = ({ item, key }: { item: ToDoClass, key: any }): void => {
   console.log(item, key);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM