You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
962 B
59 lines
962 B
2 years ago
|
import React from 'react';
|
||
|
import { Cascader } from 'antd';
|
||
|
|
||
|
interface Option {
|
||
|
code: string;
|
||
|
name: string;
|
||
|
items?: Option[];
|
||
|
}
|
||
|
|
||
|
const options: Option[] = [
|
||
|
{
|
||
|
code: 'zhejiang',
|
||
|
name: 'Zhejiang',
|
||
|
items: [
|
||
|
{
|
||
|
code: 'hangzhou',
|
||
|
name: 'Hangzhou',
|
||
|
items: [
|
||
|
{
|
||
|
code: 'xihu',
|
||
|
name: 'West Lake',
|
||
|
},
|
||
|
],
|
||
|
},
|
||
|
],
|
||
|
},
|
||
|
{
|
||
|
code: 'jiangsu',
|
||
|
name: 'Jiangsu',
|
||
|
items: [
|
||
|
{
|
||
|
code: 'nanjing',
|
||
|
name: 'Nanjing',
|
||
|
items: [
|
||
|
{
|
||
|
code: 'zhonghuamen',
|
||
|
name: 'Zhong Hua Men',
|
||
|
},
|
||
|
],
|
||
|
},
|
||
|
],
|
||
|
},
|
||
|
];
|
||
|
|
||
|
const onChange = (value: string[]) => {
|
||
|
console.log(value);
|
||
|
};
|
||
|
|
||
|
const App: React.FC = () => (
|
||
|
<Cascader
|
||
|
fieldNames={{ label: 'name', value: 'code', children: 'items' }}
|
||
|
options={options}
|
||
|
onChange={onChange}
|
||
|
placeholder="Please select"
|
||
|
/>
|
||
|
);
|
||
|
|
||
|
export default App;
|