【发布时间】:2018-07-24 18:20:10
【问题描述】:
在我的应用中有两个功能,带有单选按钮的表单和一个提交按钮。
//function that adds the selected image format to the state
handleImageFormatExportSelection(e) {
this.setState({ ImageFormatExportSelection: [e.target.value] }, () => console.log('export image as:', this.state.ImageFormatExportSelection));
}
//function that exports image in JPG format
exportJPG(e) {...}
//function that exports image in PNG format
exportPNG(e) {...}
render() {
return (
<form onSubmit={this.handleFormSubmit}>
<div className="exportAs">
<CheckboxOrRadioGroup
title={'Export image as:'}
setName={'exports'}
controlFunc={this.handleImageFormatExportSelection}
type={'radio'}
options={this.state.exportOptions}
selectedOptions={this.state.ImageFormatExportSelection} />
</div>
<button onClick={() => this.exportImage()}>Submit</button>
</form>
);
}
当用户单击按钮时,调用 exportJPG 或 exportPNG(基于单选组中的选定选项)的正确方法应该是什么?
提前感谢您对此提供的任何帮助!
【问题讨论】:
标签: javascript reactjs