2019-05-22 19:33:03 +08:00
|
|
|
---
|
|
|
|
order: 4
|
|
|
|
title:
|
|
|
|
zh-CN: 定制回填内容
|
|
|
|
en-US: Custom selection render
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
使用 `optionLabelProp` 指定回填到选择框的 `Option` 属性。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
2020-12-31 09:04:23 +08:00
|
|
|
Specify the prop name of Option which will be rendered in select box.
|
2019-05-22 19:33:03 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
2019-05-22 19:33:03 +08:00
|
|
|
import { Select } from 'antd';
|
2022-05-21 22:14:15 +08:00
|
|
|
import React from 'react';
|
2019-05-22 19:33:03 +08:00
|
|
|
|
|
|
|
const { Option } = Select;
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const handleChange = (value: string[]) => {
|
2019-05-22 19:33:03 +08:00
|
|
|
console.log(`selected ${value}`);
|
2022-05-19 09:46:26 +08:00
|
|
|
};
|
2019-05-22 19:33:03 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => (
|
2019-05-22 19:33:03 +08:00
|
|
|
<Select
|
|
|
|
mode="multiple"
|
|
|
|
style={{ width: '100%' }}
|
|
|
|
placeholder="select one country"
|
|
|
|
defaultValue={['china']}
|
|
|
|
onChange={handleChange}
|
|
|
|
optionLabelProp="label"
|
|
|
|
>
|
|
|
|
<Option value="china" label="China">
|
2019-12-23 16:22:59 +08:00
|
|
|
<div className="demo-option-label-item">
|
|
|
|
<span role="img" aria-label="China">
|
|
|
|
🇨🇳
|
|
|
|
</span>
|
|
|
|
China (中国)
|
|
|
|
</div>
|
2019-05-22 19:33:03 +08:00
|
|
|
</Option>
|
|
|
|
<Option value="usa" label="USA">
|
2019-12-23 16:22:59 +08:00
|
|
|
<div className="demo-option-label-item">
|
|
|
|
<span role="img" aria-label="USA">
|
|
|
|
🇺🇸
|
|
|
|
</span>
|
|
|
|
USA (美国)
|
|
|
|
</div>
|
2019-05-22 19:33:03 +08:00
|
|
|
</Option>
|
|
|
|
<Option value="japan" label="Japan">
|
2019-12-23 16:22:59 +08:00
|
|
|
<div className="demo-option-label-item">
|
|
|
|
<span role="img" aria-label="Japan">
|
|
|
|
🇯🇵
|
|
|
|
</span>
|
|
|
|
Japan (日本)
|
|
|
|
</div>
|
2019-05-22 19:33:03 +08:00
|
|
|
</Option>
|
2019-09-02 15:47:36 +08:00
|
|
|
<Option value="korea" label="Korea">
|
2019-12-23 16:22:59 +08:00
|
|
|
<div className="demo-option-label-item">
|
|
|
|
<span role="img" aria-label="Korea">
|
|
|
|
🇰🇷
|
|
|
|
</span>
|
|
|
|
Korea (韩国)
|
|
|
|
</div>
|
2019-05-22 19:33:03 +08:00
|
|
|
</Option>
|
2022-04-03 23:27:45 +08:00
|
|
|
</Select>
|
2019-05-22 19:33:03 +08:00
|
|
|
);
|
2022-05-19 09:46:26 +08:00
|
|
|
|
|
|
|
export default App;
|
2019-05-22 19:33:03 +08:00
|
|
|
```
|
2019-12-23 16:22:59 +08:00
|
|
|
|
|
|
|
```css
|
|
|
|
.demo-option-label-item > span {
|
|
|
|
margin-right: 6px;
|
|
|
|
}
|
|
|
|
```
|