ant-design/components/cascader/demo/search.md

82 lines
1.5 KiB
Markdown
Raw Normal View History

---
2016-12-22 16:23:33 +08:00
order: 8
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)
## 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)
2019-05-07 14:57:32 +08:00
```jsx
import { Cascader } from 'antd';
2019-05-07 14:57:32 +08:00
const options = [
{
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',
},
],
},
],
},
];
function onChange(value, selectedOptions) {
console.log(value, selectedOptions);
}
function filter(inputValue, path) {
2019-05-07 14:57:32 +08:00
return path.some(option => option.label.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
}
ReactDOM.render(
2016-09-13 11:51:34 +08:00
<Cascader
options={options}
onChange={onChange}
placeholder="Please select"
showSearch={{ filter }}
onSearch={value => console.log(value)}
2016-09-13 11:51:34 +08:00
/>,
2019-05-07 14:57:32 +08:00
mountNode,
2016-09-13 11:51:34 +08:00
);
2019-05-07 14:57:32 +08:00
```