下面的代码使用了React Modal组件:
export class AddWorkLogEditor extends React.Component {
constructor(props) {
super(props);
this.addWorkLog = this.addWorkLog.bind(this);
this.onOpenModal = this.onOpenModal.bind(this);
this.onCloseModal = this.onCloseModal.bind(this);
this.state = {
open:true
};
}
onOpenModal() {
this.setState({open: this.props.openModal});
}
onCloseModal() {
this.setState({open:false});
}
addWorkLog() {
}
render() {
const bstyle = {
backgroundColor: 'green',
textAlign:"left",
paddingLeft: '0px',
color: 'white'
};
const {open} = this.state;
return (
<div>
<Modal open={open} onClose={this.onCloseModal} little>
<h3>hi gi</h3>
<Button bsStyle="success" bsSize="small" onClick ={(ev) => {console.log(ev)} }> Save </Button>
</Modal>
</div>
);
}
}
我正在尝试使用以下代码进行调用:
addWorkLog()
{
return <AddWorkLogEditor/>;
}
和
createAddWorkLogButton () {
return (
<button style={ { color: '#007a86'} } onClick={this.addWorkLog} >Add Work Log</button>
);
}
我的意思是,当我点击这个按钮后什么也没有显示出来。有没有其他方法可以调用那个弹窗?我是从以下位置导入弹窗的:
import Modal from 'react-responsive-modal'
import Modal from 'react-responsive-modal'
Modal
已关闭,如何将showModal
的状态再次更改为 false?我尝试使用 Modal onClose,但即使确认按钮被点击,它也会被调用。 - Roni Castro