2018-12-10 22:41:22 +08:00
|
|
|
---
|
|
|
|
order: 22
|
|
|
|
title:
|
2018-12-11 18:57:53 +08:00
|
|
|
zh-CN: 隐藏已选择选项
|
2018-12-10 22:41:22 +08:00
|
|
|
en-US: Hide Already Selected
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
隐藏下拉列表中已选择的选项。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
Hide already selected options in the dropdown.
|
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
```jsx
|
2018-12-10 22:41:22 +08:00
|
|
|
import { Select } from 'antd';
|
|
|
|
|
|
|
|
const OPTIONS = ['Apples', 'Nails', 'Bananas', 'Helicopters'];
|
|
|
|
|
|
|
|
class SelectWithHiddenSelectedOptions extends React.Component {
|
|
|
|
state = {
|
|
|
|
selectedItems: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
handleChange = selectedItems => {
|
|
|
|
this.setState({ selectedItems });
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { selectedItems } = this.state;
|
|
|
|
const filteredOptions = OPTIONS.filter(o => !selectedItems.includes(o));
|
|
|
|
return (
|
|
|
|
<Select
|
|
|
|
mode="multiple"
|
|
|
|
placeholder="Inserted are removed"
|
|
|
|
value={selectedItems}
|
|
|
|
onChange={this.handleChange}
|
|
|
|
style={{ width: '100%' }}
|
|
|
|
>
|
2018-12-11 18:57:53 +08:00
|
|
|
{filteredOptions.map(item => (
|
|
|
|
<Select.Option key={item} value={item}>
|
|
|
|
{item}
|
2018-12-10 22:41:22 +08:00
|
|
|
</Select.Option>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-03 23:27:45 +08:00
|
|
|
export default () => <SelectWithHiddenSelectedOptions />;
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|