2017-08-29 39 views
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> 
&nbsp;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}>&times;</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(); 
} 

我該怎麼辦?

+0

使用的setState將調用render()。不需要做window.location.reload(); – Dev

+0

感謝兄弟,我會這樣做 – staz

回答

0


我不明白你在哪裏調用你的函數「刪除」。
無論如何,在你的狀態或道具改變時,你的組件會得到更新。 A this.setState()更新您的組件。
如果你想未經國家或道具的變化來更新你的組件,你可以可以this.forceUpdate()
我希望能幫助:)