私はUIフレームワークとしてantdを使用しています。クラスの中から宣言された関数をクラス外から呼び出そうとしていますが、どうすればいいですか?ReactJS - クラス外から関数を呼び出す
const columns = [
{
title: 'Action',
dataIndex: 'action',
key: 'action',
render: (text, record, index) => {
if (record.status === 'error') {
return <a className='error-text' href="#">{text} »</a>
} else if (record.status === 'draft') {
return <a href="#" onClick={(e) => { e.stopPropagation(); showModal(record.id); } }><Icon type="delete" /> Delete</a>
} else if (record.status === 'progress') {
return 'N/A'
} else {
return <a href="#">{text} »</a>
}
}
]
class OnBoard extends Component {
constructor(props) {
super(props);
this.state = {
modalVisible: false
}
}
showModal = (id) => {
console.log('i am clicking id: '+id);
}
render() {
return (
<Base page={this.props.location.pathname} title="TOUR LIST">
<div id="dashboard">
<Table
style={{clear: 'both'}}
dataSource={this.state.data}
columns={columns}
loading={this.state.loading}
pagination={this.state.pagination}
onChange={this.handleTableChange}
/>
<Modal
title="Delete Tour"
visible={this.state.modalVisible}
onOk={this.handleOk}
okText="Confirm"
cancelText="Cancel"
onCancel={this.handleCancel}
>
<p>Please confirm you would like to delete the Tour: blablah.xls</p>
</Modal>
</div>
</Base>
);
}
エラー: 'showModal' が定義されていない無undefを、私はそれを変更しようとした
:showModal(id){
console.log('i am clicking id: '+id);
}
しかし、私はまだ同じエラーを得た。ありません
さらに広いコンテキストを表示するためにレンダリング機能を追加しました。
できません。現在の設定にはクラスのインスタンスへの参照がありません。レンダリング関数にこのコンテキストがある場合には、それがあなたの 'OnBoard'クラスであるかどうかをチェックする必要があります。' OnBoard'クラスであれば ' this.showModal'です。 MCVE – Icepickle
を作ることができれば、あなたは 'showModal'を呼び出す場所にコードを追加できますか? –
@Icepickle私は、より多くのコンテキストのためにレンダリング機能を追加しました。 –