我正在使用antd Modal。 我有两个按钮。
但是,当同时单击两个按钮时,它将关闭。我不需要那个
index.js
this.state = {
isOpen: false,
}
handleCancel = () => {
this.setState({isOpen:false});
};
handleAddModal = () => {
var self = this;
this.setState({isOpen:true,isEdit:false,CompanyID:this.state.CompanyID,selectedItem:null,fields: {
RegisterID: { value: '',},
CustomerID: { value: '',},
AccountID: { value: '',},
}});
};
handleSave = (state) => {
this.setState({
isOpen:state.isOpen
});
};
<RegisterForm
showLoader={this.showLoader}
visible={this.state.isOpen}
/>
RegisterForm.js
this.state={saveOrClose:false}
handleClear = () => {
this.props.form.resetFields()
};
handleCancel = () => {
this.props.handleCancel()
};
handleSubmit = (e,isNewAdd) => {
this.setState({saveOrClose:isNewAdd})
let val = Object.assign({'CompanyID':this.props.CompanyID.value},values);
this.props.actions.register.AddRegister(val);
if(!isNewAdd){
this.handleClear();
this.props.handleSave(false);}
});
};
render(){
<Modal
visible={visible}
title=
"Register Form"
className="dialog-container"
onCancel={this.handleCancel}
footer={[
<Button className="save-btn" onClick={(event) => this.handleSubmit(event,true)}
style={{'visibility' : this.props.RegisterID.value === '' ? 'visible' : 'hidden'}}>Save and Add </Button>,
<Button className="save-btn" onClick={(event) => this.handleSubmit(event,false)}>
{this.props.isEdit ? "Save" :"Save and Close" }</Button>, //Edit Button
]}>
}
我试图通过在Button的onClick
函数上传递布尔值来编写条件。
如何对此进行实际编码,以便获得所需的结果? 逻辑上有什么错误吗? 还有其他方法可以实现吗?
答案 0 :(得分:0)
handleSubmit = (e,isNewAdd) => {
this.setState({saveOrClose:isNewAdd})
let val = Object.assign({'CompanyID':this.props.CompanyID.value},values);
this.props.actions.register.AddRegister(val);
if(!isNewAdd){
this.handleClear();
this.props.handleSave(false);}
});
};