根据
antd
document
,
Select
可以从中指定标签值
Option
道具
optionLabelProp
,在本用例中可以从中获取值
country.code
.
用于扩展的大小
选项
基于其内容,
dropdownMatchSelectWidth
可以设置
false
,因此
选项
不限于的大小
选择
.
修改了演示:
codesandbox
<Select
defaultValue="Japan"
onChange={handleChange}
// ð Specify label prop here
optionLabelProp="label"
// ð Set Option to be extendable by content here
dropdownMatchSelectWidth={false}
>
{countryNames.map((country) => (
<Option
key={country.name}
value={country.name}
// ð Give label value for Select here
label={country.code}
>
{`${country.code} ${country.name}`}
</Option>
))}
</Select>