【发布时间】:2017-08-29 08:44:00
【问题描述】:
大家好,我是 Reactjs 的新手。当我单击模式中的删除按钮时,我很难重新加载我的渲染。我希望在单击按钮后,渲染应该重新加载而不重新加载页面。
这是我的一些代码:
render (
....
<button className="btn btn-black btn-myproducts-delete"
data-toggle="modal" onClick={ this.assignId.bind(null, data.id) }>
<span className="glyphicon glyphicon-trash"></span>
Delete</button>
)
我的模态
<Modal isOpen={ this.state.showModal }
onRequestClose={ this.closeModal }
style={customStyles}
contentLabel="Delete">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<button type="button" className="close" onClick={this.closeModal}>×</button>
<h4 className="modal-title">Delete</h4>
</div>
<div className="modal-body">
<p>Are you sure you want to delete this?
You cannot undo this method.</p>
</div>
<div className="modal-footer">
<button type="button" className="btn btn-danger"
onClick={this.deleteProduct.bind(null, this.state.productId)}>Delete</button>
<button type="button" className="btn btn-default" onClick={this.closeModal}>
Cancel
</button>
</div>
</div>
</div>
</Modal>
用于删除
delete = (idd) => {
const { actions } = this.props;
actions.delete(id);
this.setState({showModal: false});
window.location.reload();
}
我该怎么办?
【问题讨论】:
-
使用 setState 将调用 render()。不需要做 window.location.reload();
-
谢谢兄弟,我会这样做的
标签: reactjs modal-dialog atom-editor