单击更新按钮时,模式会弹出两次,第一个显示正确的 item.id,但第二个是列表中的最后一个值。任何帮助表示赞赏。尝试在模态标签内添加 {this.props.child} 但它不起作用。
任何帮助,将不胜感激。
this.state = {
ModalText: 'Content of the modal',
visible: false,
currentId : 0,
confirmLoading: false,
}
}
showModal = () => {
this.setState({
visible: true,
});
}
handleOk = () => {
this.setState({
ModalText: 'The modal will be closed after two seconds',
confirmLoading: true,
});
setTimeout(() => {
this.setState({
visible: false,
confirmLoading: false,
});
}, 2000);
}
handleCancel = () => {
console.log('Clicked cancel button');
this.setState({
visible: false,
});
}
render(){
const { visible, confirmLoading, ModalText } = this.state;
return(
<div>
<ul>
{this.props.user.map(item => (
<li key={item.id}>
The person is {item.name} and the his/her email is
{item.email}.
<Button type="primary" onClick={this.showModal}>
Update
</Button>
<Modal title="Title"
visible={visible}
onOk={this.handleOk}
confirmLoading={confirmLoading}
onCancel={this.handleCancel}
>
{item.id}
<UpdateModal/>
</Modal>
</li>
))}
</ul>
</div>
)
}
}