0
嗨,大家好,我是Reactjs的新手。當我點擊模式中的刪除按鈕時,我很難重新加載渲染。我想要點擊按鈕後,渲染應該重新加載而不重新加載頁面。如何在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(); – Dev
感謝兄弟,我會這樣做 – staz