考虑这个
render() {
const { gender } = this.state
}
return (
<div>
<FormControl variant="outlined">
<InputLabel>Gender</InputLabel>
<Select id="dropdown">
<MenuItem value={10}>Male</MenuItem>
<MenuItem value={20}>Female</MenuItem>
</Select>
</FormControl>
</div>
当它加载时,我只想预先选择“男性”,因为 const 性别等于“男性”。例如,在加载时它应该如下所示:
我试过穿上document.getElementById("dropdown").selectedIndex = "0";componentDidMount,但没有用。这通常适用于正常的选择/选项
我如何实现这一目标?
