我有一个名为<ImageVoteItem/>
的ReactJS组件。我有一个名为'Add Option'
的按钮。当我点击这个按钮<ImageVoteItem/>
应该出现。当我再次点击该按钮时,应该出现另一个<ImageVoteItem/>
组件。呈现新元素onClick
我已经完成了这种使用状态。但我只能渲染一个<ImageVoteItem/>
组件。当我点击'Add Option'
按钮时,如何反复渲染相同的组件?
我班
class ImageVotePost extends Component {
constructor() {
super();
this.state = {
addOption: false,
}
this.addOption = this.addOption.bind(this);
}
addOption() {
this.setState({
addOption: true,
})
}
render() {
return (
<div className="padding5px margin_bottom10px">
<ImageVoteItem/>
<ImageVoteItem/>
{this.state.addOption ? <ImageVoteItem/> : null}
<div className="image_add_btn border" onClick={this.addOption}>
<div className="width_100 relative_position">
<img src={plus} className="plus_icon"/>
<a className="add_opt_text">Add Option</a>
</div>
<input type="file" id="src" className="filetype2"/>
</div>
</div>
)
}
}
谢谢你在工作 – CraZyDroiD