简体   繁体   English

在reactJs中显示引导程序模态

[英]Displaying bootstrap modal in reactJs

I am trying to display a bootstrap modal in my reactJs project. 我试图在我的reactJs项目中显示一个引导模式。 I have buttons with different IDs with different content displayed in a map function. 我在地图功能中显示具有不同ID和不同内容的按钮。 I want the each modal content to correspond to the ID of the button clicked. 我希望每个模式内容都对应于单击的按钮的ID。 I am following this examaple - https://react-bootstrap.github.io/components/modal/ but there is no way to specify the id here. 我下面这个examaple - https://react-bootstrap.github.io/components/modal/但没有办法在这里指定的ID。

How do I resolve this? 我该如何解决?

At button, you can pass content to onClick and set it to state 在按钮处,您可以将内容传递给onClick并将其设置为state

handleShow = (data) => {
    this.setState({ show: true, title: data.title });
  }
render() {
return (
<div>
{
listData.map((data, index) => {
   return (
       <Button key={index} bsStyle="primary" bsSize="large" onClick={() => this.handleShow(data)}>
          Launch demo modal
       </Button>
   );
})
}
</div>
<Modal show={this.state.show} onHide={this.handleClose}>
    <Modal.Body>
        {this.state.title}
    </Modal.Body>
</Modal>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM