mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-16 01:29:11 +08:00
2cdf586291
* chore: fix lint * chore: fix lint * test: fix 16 * fix: lint
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
import React, { useState } from 'react';
|
|
import { Cascader } from 'antd';
|
|
|
|
interface Option {
|
|
value?: string | number | null;
|
|
label: React.ReactNode;
|
|
children?: Option[];
|
|
isLeaf?: boolean;
|
|
}
|
|
|
|
const optionLists: Option[] = [
|
|
{
|
|
value: 'zhejiang',
|
|
label: 'Zhejiang',
|
|
isLeaf: false,
|
|
},
|
|
{
|
|
value: 'jiangsu',
|
|
label: 'Jiangsu',
|
|
isLeaf: false,
|
|
},
|
|
];
|
|
|
|
const App: React.FC = () => {
|
|
const [options, setOptions] = useState<Option[]>(optionLists);
|
|
|
|
const onChange = (value: (string | number)[], selectedOptions: Option[]) => {
|
|
console.log(value, selectedOptions);
|
|
};
|
|
|
|
const loadData = (selectedOptions: Option[]) => {
|
|
const targetOption = selectedOptions[selectedOptions.length - 1];
|
|
|
|
// load options lazily
|
|
setTimeout(() => {
|
|
targetOption.children = [
|
|
{
|
|
label: `${targetOption.label} Dynamic 1`,
|
|
value: 'dynamic1',
|
|
},
|
|
{
|
|
label: `${targetOption.label} Dynamic 2`,
|
|
value: 'dynamic2',
|
|
},
|
|
];
|
|
setOptions([...options]);
|
|
}, 1000);
|
|
};
|
|
|
|
return <Cascader options={options} loadData={loadData} onChange={onChange} changeOnSelect />;
|
|
};
|
|
|
|
export default App;
|