【问题标题】:How to reload a render in reactjs如何在 reactjs 中重新加载渲染
【发布时间】: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>
&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();
}

我该怎么办?

【问题讨论】:

  • 使用 setState 将调用 render()。不需要做 window.location.reload();
  • 谢谢兄弟,我会这样做的

标签: reactjs modal-dialog atom-editor


【解决方案1】:


我不明白你在哪里调用你的函数“删除”。
无论如何,作为反应,当您的状态或道具更改时,您的组件会更新。 this.setState() 更新您的组件。
如果你想在不改变状态或道具的情况下更新你的组件,你可以this.forceUpdate()
希望能帮到你:)

【讨论】:

    猜你喜欢
    • 2019-07-20
    • 2018-07-20
    • 2021-08-22
    • 2017-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    相关资源
    最近更新 更多