1 回答
TA贡献1155条经验 获得超0个赞
let items = [];
Object.entries(this.languagesKey()).forEach(([key, value], index) => {
items.push(<MenuItem key={index} value={key}>{value}</MenuItem>);
});
<FormControl>
<InputLabel htmlFor="nativeLanguageSelect">Select Language You Already Know</InputLabel>
<Select
onChange={ this.nativeLanguageChange }
inputProps={{
name: 'nativeLanguage',
id: 'nativeLanguageSelect'
}}
value={ this.state.nativeLanguage }
>
{ items }
</Select>
</FormControl>
推荐使用 .map 以方便使用
您需要数组才能使用地图。例子。
<FormControl>
<InputLabel htmlFor="nativeLanguageSelect">Select Language You Already Know</InputLabel>
<Select
onChange={ this.nativeLanguageChange }
inputProps={{
name: 'nativeLanguage',
id: 'nativeLanguageSelect'
}}
value={ this.state.nativeLanguage }
>
{Object.keys(this.languagesKey()).map(option =>
<MenuItem key={option} value={option}>{this.languagesKey()[option]}</MenuItem>
)}
</Select>
</FormControl>
添加回答
举报