2016-09-01 11:08:41 +08:00
|
|
|
---
|
2016-12-22 16:23:33 +08:00
|
|
|
order: 8
|
2016-09-01 11:08:41 +08:00
|
|
|
title:
|
|
|
|
zh-CN: 搜索
|
|
|
|
en-US: Search
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
可以直接搜索选项并选择。
|
|
|
|
|
2017-03-29 15:39:10 +08:00
|
|
|
> `Cascader[showSearch]` 暂不支持服务端搜索,更多信息见 [#5547](https://github.com/ant-design/ant-design/issues/5547)
|
|
|
|
|
2016-09-01 11:08:41 +08:00
|
|
|
## en-US
|
|
|
|
|
|
|
|
Search and select options directly.
|
|
|
|
|
2017-03-29 15:39:10 +08:00
|
|
|
> Now, `Cascader[showSearch]` doesn't support search on server, more info [#5547](https://github.com/ant-design/ant-design/issues/5547)
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
2016-09-01 11:08:41 +08:00
|
|
|
import { Cascader } from 'antd';
|
2022-05-19 09:46:26 +08:00
|
|
|
import type { DefaultOptionType } from 'antd/es/cascader';
|
2022-05-21 22:14:15 +08:00
|
|
|
import React from 'react';
|
2016-09-01 11:08:41 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
interface Option {
|
|
|
|
value: string;
|
|
|
|
label: string;
|
|
|
|
children?: Option[];
|
|
|
|
disabled?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
const options: Option[] = [
|
2019-05-07 14:57:32 +08:00
|
|
|
{
|
|
|
|
value: 'zhejiang',
|
|
|
|
label: 'Zhejiang',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
value: 'hangzhou',
|
|
|
|
label: 'Hangzhou',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
value: 'xihu',
|
|
|
|
label: 'West Lake',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'xiasha',
|
|
|
|
label: 'Xia Sha',
|
|
|
|
disabled: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'jiangsu',
|
|
|
|
label: 'Jiangsu',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
value: 'nanjing',
|
|
|
|
label: 'Nanjing',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
value: 'zhonghuamen',
|
|
|
|
label: 'Zhong Hua men',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
2016-09-01 11:08:41 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const onChange = (value: string[], selectedOptions: Option[]) => {
|
2016-12-07 10:43:06 +08:00
|
|
|
console.log(value, selectedOptions);
|
2022-05-19 09:46:26 +08:00
|
|
|
};
|
2016-09-01 11:08:41 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const filter = (inputValue: string, path: DefaultOptionType[]) =>
|
|
|
|
path.some(
|
|
|
|
option => (option.label as string).toLowerCase().indexOf(inputValue.toLowerCase()) > -1,
|
|
|
|
);
|
2018-03-09 00:47:38 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => (
|
2016-09-13 11:51:34 +08:00
|
|
|
<Cascader
|
|
|
|
options={options}
|
|
|
|
onChange={onChange}
|
|
|
|
placeholder="Please select"
|
2018-03-09 00:47:38 +08:00
|
|
|
showSearch={{ filter }}
|
2021-12-30 11:38:48 +08:00
|
|
|
onSearch={value => console.log(value)}
|
2022-04-03 23:27:45 +08:00
|
|
|
/>
|
2016-09-13 11:51:34 +08:00
|
|
|
);
|
2022-05-19 09:46:26 +08:00
|
|
|
|
|
|
|
export default App;
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|