我有一个“模态”组件和另一个在这个模态上动态插入“childs”的元素。如何从模态子项中调用父元素的方法:
class Parent extends Component {
constructor(props) {
super(props);
this.state = {
'view_addevent': false,
};
this.addEventAdHoc = this.addEventAdHoc.bind(this);
this.closeEventAdHoc = this.closeEventAdHoc.bind(this);
this.searchAdHocEvent = this.searchAdHocEvent(this);
}
addEventAdHoc() {
this.setState({ view_addevent: true });
}
closeEventAdHoc() {
this.setState({ view_addevent: false })
}
searchAdHocEvent(event) {
console.log(event.keyCode);
}
render() {
return (
<main id='main-content'>
<Modal show={this.state.view_addevent} autocomplete={ this.searchAdHocEvent } close={ this.closeEventAdHoc }>
<div className='form-group'>
<input id='event-adhoc-search' onKeyPress={(e) => this.props.autocomplete(e) } className='form-control' type='text' />
</div>
</Modal>
</main>
);
}
}