Jos*_*iga 5 modal-dialog jsx ecmascript-6 reactjs
下一个代码使用模态反应组件:
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>
);
}
}
Run Code Online (Sandbox Code Playgroud)
我试图用它来调用它:
addWorkLog()
{
return <AddWorkLogEditor/>;
}
Run Code Online (Sandbox Code Playgroud)
和
createAddWorkLogButton () {
return (
<button style={ { color: '#007a86'} } onClick={this.addWorkLog} >Add Work Log</button>
);
}
Run Code Online (Sandbox Code Playgroud)
我的意思是,点击此按钮后没有任何显示.还有另一种方式来调用该模态吗?我从以下位置导入模态:
从'react-responsive-modal'导入模态
Dmi*_*nko 13
您只是在单击按钮时尝试渲染模态,而对于非反应环境则非常自然,反应它以不同的方式工作.在最简单的解决方案中,Modal应始终呈现,当用户单击按钮时,您将模态open属性更改为true.
{ /* all the markup of your page */ }
<button onClick={() => this.setState({showModal: true})}>Add Work Log</button>
{ /* anything else */ }
{ /* modal is here but it is hidden */ }
<Modal open={this.state.showModal}>...</Modal>
Run Code Online (Sandbox Code Playgroud)
或者,你可以跳过模态渲染,直到showModal变为真.
this.state.showModal && <Modal open>...</Modal>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23717 次 |
| 最近记录: |