我正在使用反应式自举并使用旋转木马。要从选项选择旋转木马项目和开放的模式,但未能如愿任何帮助旋转木马 - 我如何选择旋转木马项目并从选择中打开模式
1
A
回答
0
我首先包裹Carousel.Item
成分,并添加一个模式,然后单击处理到包装实例,类似也许下面
class Item extends Component {
constructor() {
super();
this.state = {
show: false
};
}
render() {
const { caption, title, src, alt, className, modal } = this.props;
return (
<Carousel.Item>
<img
className={className}
src={src}
alt={alt}
onClick={e => this.setState({ show: true })}
/>
<Carousel.Caption>
<h1>
{title}
</h1>
<p>
{caption}
</p>
</Carousel.Caption>
{/* --> modal instance <-- */}
<Modal
show={this.state.show}
onHide={() => this.setState({ show: false })}
>
<Modal.Header closeButton>
<Modal.Title id="contained-modal-title">
{modal.title}
</Modal.Title>
</Modal.Header>
<Modal.Body>
{modal.content}
</Modal.Body>
<Modal.Footer>
<Button onClick={() => this.setState({ show: false })}>
Close
</Button>
</Modal.Footer>
</Modal>
{/* --> end modal instance <-- */}
</Carousel.Item>
);
}
}
接下来,我会在我的Carousel
组件,如下
class MyCarousel extends Component {
constructor() {
super();
this.state = {
items: [
{
caption: "blah 1",
title: "blah 1",
src: "/path/to/image",
alt: "blah 1"
},
{
caption: "blah 2",
title: "blah 2",
src: "/path/to/another/image",
alt: "blah 2"
}
]
};
this.renderItems = this.renderItems.bind(this);
}
renderItems() {
const { items } = this.state;
items.map(item => {
const modal = {
title: item.title,
content: item.caption
};
return <Item key={item.title} {...item} modal={modal} />;
});
}
render() {
return (
<Carousel>
{this.renderItems()}
</Carousel>
);
}
}
相关问题
- 1. 旋转木马内的旋转木马
- 2. 引导旋转木马:旋转木马
- 3. 旋转木马
- 4. 如何让旋转木马滚动旋转木马Bootstrap
- 5. 选择'项目'2负载 - 猫头鹰旋转木马
- 6. 旋转木马博
- 7. jquery旋转木马
- 8. Papervision旋转木马
- 9. Bootstrap旋转木马
- 10. JavaScript旋转木马
- 11. iPhone - 旋转木马
- 12. 如何旋转木马
- 13. Bootstrap旋转木马控制旋转木马之外
- 14. 父级旋转木马里面的儿童旋转木马js
- 15. 旋转木马 - 将不同页面添加到旋转木马
- 16. 如何使用extjs旋转木马选项卡项目
- 17. 旋转木马缩略图,添加类到下一个旋转木马旋转
- 18. 多项目响应旋转木马
- 19. 刷新旋转木马项目
- 20. 旋转木马滑块与筛选
- 21. Bootstrap旋转木马:以动画方式在旋转木马中设置图像
- 22. WPF旋转木马/旋转元件
- 23. 使Android旋转木马自动旋转
- 24. 旋转木马模式内不工作
- 25. Bootstrap 2旋转木马模式内
- 26. Umbraco旋转木马内容
- 27. 旋转木马滚动?
- 28. jQuery的3D旋转木马
- 29. 让旋转木马停止
- 30. 定制YUI旋转木马
分享更多的信息,代码片段等。'反应,modal'包是一个很好的组件来使用的情态动词使用。 –
const MyCarousel2 =({items})=>
在这里,我的旋转木马显示的项目列表,我想点击旋转木马选择项目属性,并打开模式绕过属性 – Vin