我要关闭弹出窗口,我该怎么做?

时间:2019-04-22 09:25:01

标签: javascript reactjs redux popup

当我按下func a() { c() } func b() { c() } func c() { print("hello world") } 组件中的AddAction按钮时,我希望弹出窗口关闭。 ?

实际上,如果我在AddAction组件弹出的组件中到达Addaction方法,我的问题将得到解决。

AddAction组件:

onCloseAddActionModal

2 个答案:

答案 0 :(得分:0)

onCloseAddActionModal组件渲染prop组件时,您可以简单地将AddAction方法传递为OffBoarding。然后,您可以在“添加操作”按钮上点击该传递的函数作为道具,即

因此,在您的弹出组件中,更改以下内容:

 <AddAction id= 
      {this.state.carid} 
      close={this.state.openAddAction}/>

对此(作为道具传递函数):

<AddAction id= 
      {this.state.carid} 
      close={this.state.openAddAction}
      closeDialog={this.onCloseAddActionModal}/>

然后在您的AddAction组件中,更改以下内容:

  <button
   onClick={() => 
   this.fetchAdd(this.props.id, this.state.selectId)}
   className="btn btn-primary popupAddAction--btn">
     Add Action
   </button>

对此(调用函数在上一步中作为prop传递):

<button
  onClick=
  {() =>{ 
  this.fetchAdd(this.props.id, this.state.selectId);
  this.props.closeDialog();
  }}
  className="btn btn-primary popupAddAction--btn">
  Add Action
 </button>

答案 1 :(得分:0)

如果openAddAction标志为true,则只有addaction组件将正确显示。代替打开和关闭模态,将以下代码添加到模态,并在获取方法的添加动作模态中将openAddAction设置为false。在您的代码中,您可以从子级到父级进行通信,但是您尝试基于子级关闭模态,但是模态存在于父级中,因此请通过

将该传递函数与父级到子级进行通信
 <Modal isOpen = {this.state.openAddAction} center>
        <AddAction id= {this.state.carid}  
          closeModa={this.onCloseAddActionModal} />
 </Modal>

在addAction模式下,您必须像这样添加

fetchAdd = (carid, offboardingactiontypeid) => {
    this.setState({openAddAction:false});
    this.props.onCloseAddActionModal();
}

在fetchAdd方法中调用此closeModal方法