我要设置
selected={( props.eSimStore.showAnswerFlag &&
String.fromCharCode(65 + index) == props.eSimStore.question.answer )}
作为触发onChange(event)
方法的事件。在我选择的代码中,此方法有效,但未设置为事件,因此未设置为props.setNewAnswer(String.fromCharCode(65 + index))
。请有人提供解决方案。
<select
onChange={(event) => {
if (props.eSimStore.examMode != 'read') {
let index= +event.target.value;
props.setNewAnswer(String.fromCharCode(65 + index));
}}}
> {
props.eSimStore.question.options.map((option, index) => (
<option
key = {index}
selected={( props.eSimStore.showAnswerFlag &&
String.fromCharCode(65 + index) == props.eSimStore.question.answer)}
value = {index}
>{htmlToReactParser.parse(option)}</option> ))}
</select>