【发布时间】:2018-09-14 13:24:29
【问题描述】:
我在父级中设置了模态组件的状态以处理打开和关闭它。初始显示状态为假,在单击事件时显示状态变为真并出现模式弹出窗口。这工作正常,问题是我无法关闭它。我似乎无法从子组件调用父组件中的 handleHide 函数。
class Parent extends Component {
constructor(props) {
super(props);
this.handleHide = this.handleHide.bind(this);
this.state = {
show: false
};
}
handleHide() {
this.setState({ show: false });
}
renderRow() {
return (
<tr>
<td onClick={() => this.setState({ show: true })}>test</td>
<ChildModal show={this.state.show} handleHide={this.handleHide}/>
</tr>
);
}
}
class ChildModal extends Component {
render() {
return (
<Modal onHide={() => this.props.handleHide()} show={this.props.show}>
<Modal.Header closeButton>
<Modal.Title>Test</Modal.Title>
</Modal.Header>
<Modal.Body>
{/* some text */}
</Modal.Body>
</Modal>
);
}
}
【问题讨论】:
-
得到了解决方案......我也遇到了类似的问题......请在这里更新......提前谢谢
标签: reactjs