mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-12 07:09:55 +08:00
91821d4d3a
* feat: select edit demo to data driven * feat: edit demo to data driven Co-authored-by: 二货机器人 <smith3816@gmail.com>
44 lines
838 B
Markdown
44 lines
838 B
Markdown
---
|
|
order: 22
|
|
title:
|
|
zh-CN: 隐藏已选择选项
|
|
en-US: Hide Already Selected
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
隐藏下拉列表中已选择的选项。
|
|
|
|
## en-US
|
|
|
|
Hide already selected options in the dropdown.
|
|
|
|
```tsx
|
|
import { Select } from 'antd';
|
|
import React, { useState } from 'react';
|
|
|
|
const OPTIONS = ['Apples', 'Nails', 'Bananas', 'Helicopters'];
|
|
|
|
const App: React.FC = () => {
|
|
const [selectedItems, setSelectedItems] = useState<string[]>([]);
|
|
|
|
const filteredOptions = OPTIONS.filter(o => !selectedItems.includes(o));
|
|
|
|
return (
|
|
<Select
|
|
mode="multiple"
|
|
placeholder="Inserted are removed"
|
|
value={selectedItems}
|
|
onChange={setSelectedItems}
|
|
style={{ width: '100%' }}
|
|
options={filteredOptions.map(item => ({
|
|
value: item,
|
|
label: item,
|
|
}))}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default App;
|
|
```
|