如何将答案保存在selectOption数组中? 考试阵列内部有问题 和selectOption数组必须具有用户选择的答案
constructor(props) {
super(props);
this.handleOptionChange = this.handleOptionChange.bind(this);
this.state = {
exams: [],
selectedOption:[],
};
}
getStepContent(step) {
let i = 0
for (i=0; i < this.state.exams.length;i++){
switch (step) {
case i:
return(
<div>
<div>
<FormControl component="fieldset">
<FormLabel className="QuestionBox" >{i+1}-{this.state.exams[i].text}</FormLabel>
<RadioGroup value={this.state.selectedOption[i]} onChange={this.handleOptionChange}>
<FormControlLabel checked={this.state.selectedOption[i] === this.state.exams[i].ig1} value={this.state.exams[i].ig1} onChange={this.handleOptionChange} control={<Radio />} label={this.state.exams[i].ig1} />
<FormControlLabel checked={this.state.selectedOption[i] === this.state.exams[i].ig2} value={this.state.exams[i].ig2} onChange={this.handleOptionChange} control={<Radio />} label={this.state.exams[i].ig2} />
<FormControlLabel checked={this.state.selectedOption[i] === this.state.exams[i].ig3} value={this.state.exams[i].ig3} onChange={this.handleOptionChange} control={<Radio />} label={this.state.exams[i].ig3} />
<FormControlLabel checked={this.state.selectedOption[i] === this.state.exams[i].ig4} value={this.state.exams[i].ig4} onChange={this.handleOptionChange} control={<Radio />} label={this.state.exams[i].ig4} />
</RadioGroup>
</FormControl>
</div>
</div>
);