我用react和bootstrap构建了这个项目。我想要更改为material-ui,在更改单选按钮之前,它工作得很好。
这是我用过的旧版本(效果很好)。
<label>
<input type= {that.props.questionType} name={that.props.questionID} value={choice}/>
{choice}
</label>
这是material-ui版本。
<RadioButtonGroup >
<RadioButton
value={that.props.questionID}
label={choice}
/>
</RadioButtonGroup>
下面是我用来生成单选按钮的map函数:
var iterator = (
<RadioButtonGroup selectedValue={that.props.questionID}>
{that.props.questionChoices.map(choice => <RadioButton value={choice} label={choice} /> )}
</RadioButtonGroup>
);
发布于 2018-06-03 01:43:46
创建RadioButtonGroup时,必须分配name属性(请参阅material-ui documentation)。
此外,在使用映射函数时,您应该为每个返回的元素添加一个键属性。
下面的代码片段解决了这些问题:
var iterator = (
<RadioButtonGroup
name="questionChoices"
valueSelected={that.props.questionID}
onChange={that.props.handleChange}
>
{that.props.questionChoices.map(choice => (
<RadioButton value={choice} label={choice} key={choice}/>
)}
</RadioButtonGroup>
)
https://stackoverflow.com/questions/48360936
复制相似问题