reactjs - 模态不会出现在反应中
问题描述
我正在使用 react-bootstrap,并且我在组件函数中有一个 Modal,如下所示:
// stateless function component
function ServiceModal(props) {
return (
<Modal>
<Modal.Dialog>
<Modal.Header>
<Modal.Title>{props.item.name}</Modal.Title>
</Modal.Header>
<Modal.Body>
<p>{props.item.id}</p>
<p>{props.item.name}</p>
<p>{props.item.description}</p>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary">Close</Button>
</Modal.Footer>
</Modal.Dialog>
</Modal>
);
}
这个模态没有出现。内容不显示,甚至覆盖。这是我如何调用它来渲染它:
class Service extends Component {
renderServiceModal(service) {
return (
<ServiceModal
item={service}
/>
);
}
render() {
return (
<div className="container content">
<div className="row">
<div className="col-6">
<form>
<div className="form-group">
<label htmlFor="nom">Name</label>
<input name="name" ref="name" type="text" className="form-control" id="name" placeholder="Name"
onChange={(value) => this.onChange(value)} />
</div>
<div className="row">
<div className="col-sm-3">
<button onClick={this.postService.bind(this)} type="submit" className="btn btn-primary btn-block">Add</button>
</div>
</div>
</form>
</div>
<div className="col-6">
<ul className="list-group">
{this.state.services.map(service =>
<li onClick={() => { this.readOneService(service.id) }} className="list-group-item" key={service.id}>{service.nom}
<div className="btn-group btn-group-sm float-right" role="group">
<button type="button" className="btn btn-primary"
onClick={() => this.updateService(service.id)}>Update
</button>
<button type="button" className="btn btn-danger"
onClick={() => this.deleteService(service.id)}>Delete
</button>
</div>
</li>
)}
</ul>
</div>
</div>
</div>
);
}
什么都没有显示...有什么帮助吗?
编辑:在我的主组件中使用渲染内的代码更新问题
解决方案
默认情况下,模式是隐藏的:https ://react-bootstrap.github.io/components/modal/#modals-props
您需要将该show
属性设置为 true: ( <Modal show={true}>
)
完整代码
// stateless function component
function ServiceModal(props) {
return (
<Modal show={true}>
<Modal.Dialog>
<Modal.Header>
<Modal.Title>{props.item.name}</Modal.Title>
</Modal.Header>
<Modal.Body>
<p>{props.item.id}</p>
<p>{props.item.name}</p>
<p>{props.item.description}</p>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary">Close</Button>
</Modal.Footer>
</Modal.Dialog>
</Modal>
);
}
推荐阅读
- java - java中的常量含义
- java - 如何编写返回具有java8特性的字符串的for循环?
- module - 如何在 azure terraform 中访问模块 [NIC] 输出到另一个模块 [VM] 的元组值类型列表
- react-native - 当应用程序处于后台或终止状态时,抬头或通知横幅不会从顶部弹出|| 反应原生火力基地 || fcm
- javascript - TranslateService 无法翻译日期字符串不正确
- linux - I want to move whole mongo databse to linux
- jsp - 为什么Tomcat在导入普通对象时会出错?
- javascript - 如何使用默认导出保留“实时绑定”
- c - 如何从C中的函数获取字符串作为返回值?
- swift - 参数类型(字符串)->()的问题-SwiftUI