Reactjs 如何在列内的呈现中传递函数(作用域问题)

Reactjs 如何在列内的呈现中传递函数(作用域问题),reactjs,antd,Reactjs,Antd,我的作用域有问题,如何访问标题中的showmodel函数?在这个标题中,我有一个名为lastWinners的列,它呈现一个按钮,在这个按钮中,我想在按下时显示一个模式,但我得到一个typeError:无法读取undefined的属性“showModal” export class EventsList extends React.Component { constructor(props) { super(props) } state = { visible: false

我的作用域有问题,如何访问标题中的showmodel函数?在这个标题中,我有一个名为lastWinners的列,它呈现一个按钮,在这个按钮中,我想在按下时显示一个模式,但我得到一个typeError:无法读取undefined的属性“showModal”

export class EventsList extends React.Component {
  constructor(props) {
    super(props)
  }

  state = { visible: false };

  showModal = () => {
    this.setState({
      visible: true,
    });
  };

  handleOk = e => {
    console.log(e);
    this.setState({
      visible: false,
    });
  };

  handleCancel = e => {
    console.log(e);
    this.setState({
      visible: false,
    });
  };

  render() {
    const { schema, loadEvents, match } = this.props
    return (
      <Card title='Eventos' bordered={false}>
        <DataTable
          dataLoader={loadEvents}
          header={header}
            
        />
        <Modal
          title="Basic Modal"
          visible={this.state.visible}
          onOk={this.handleOk}
          onCancel={this.handleCancel}
        ></Modal>
      </Card>
    )
  }
}

const header = {
  id: { title: 'ID' },
  winnersQuantity: { title: 'Quantidade de vencedores' },
  lastWinners: {
    title: 'Ganhadores',
    render: () => (
      <Button
        onClick={this.showModal} <--------- typeError: Cannot read property 'showModal' of undefined
      >
        <Icon type='trophy' />
      </Button>
    ),
  },
}
导出类事件列表扩展React.Component{
建造师(道具){
超级(道具)
}
状态={visible:false};
showModal=()=>{
这是我的国家({
可见:对,
});
};
handleOk=e=>{
控制台日志(e);
这是我的国家({
可见:假,
});
};
handleCancel=e=>{
控制台日志(e);
这是我的国家({
可见:假,
});
};
render(){
const{schema,loadEvents,match}=this.props
返回(
)
}
}
常数头={
id:{title:'id'},
WinnerQuantity:{title:'Quantidade de vencedores'},
最后获奖者:{
标题:“甘哈多雷斯”,
渲染:()=>(

您必须将该方法绑定到类,或者在将其作为prop传递时使用arrow函数,以便正确定义

绑定函数

  constructor(props) {
    super(props)
    this.showModal = this.showModal.bind(this);
  }
或者在箭头函数中传递它

      <Button onClick={() => this.showModal()}>
        <Icon type='trophy' />
      </Button>
this.showmodel()}>

相同错误类型错误:无法读取未定义的属性“showModal”