2016-03-31 09:40:55 +08:00
|
|
|
---
|
|
|
|
order: 0
|
2016-08-05 11:47:31 +08:00
|
|
|
title:
|
|
|
|
zh-CN: 基本
|
|
|
|
en-US: Basic
|
2016-03-31 09:40:55 +08:00
|
|
|
---
|
2015-12-28 19:16:02 +08:00
|
|
|
|
2016-08-05 11:47:31 +08:00
|
|
|
## zh-CN
|
|
|
|
|
2015-12-28 19:16:02 +08:00
|
|
|
最简单的用法。
|
|
|
|
|
2016-08-05 11:47:31 +08:00
|
|
|
## en-US
|
|
|
|
|
|
|
|
The most basic usage.
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
2015-12-28 19:16:02 +08:00
|
|
|
import { TreeSelect } from 'antd';
|
2022-05-23 14:37:16 +08:00
|
|
|
import React, { useState } from 'react';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2022-09-19 11:00:17 +08:00
|
|
|
const treeData = [
|
|
|
|
{
|
|
|
|
value: 'parent 1',
|
|
|
|
title: 'parent 1',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
value: 'parent 1-0',
|
|
|
|
title: 'parent 1-0',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
value: 'leaf1',
|
|
|
|
title: 'leaf1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'leaf2',
|
|
|
|
title: 'leaf2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'parent 1-1',
|
|
|
|
title: 'parent 1-1',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
value: 'leaf3',
|
|
|
|
title: <b style={{ color: '#08c' }}>leaf3</b>,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => {
|
|
|
|
const [value, setValue] = useState<string | undefined>(undefined);
|
|
|
|
|
|
|
|
const onChange = (newValue: string) => {
|
|
|
|
setValue(newValue);
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2022-05-19 09:46:26 +08:00
|
|
|
|
2021-03-08 18:06:49 +08:00
|
|
|
return (
|
|
|
|
<TreeSelect
|
|
|
|
showSearch
|
|
|
|
style={{ width: '100%' }}
|
|
|
|
value={value}
|
|
|
|
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
|
|
|
placeholder="Please select"
|
|
|
|
allowClear
|
|
|
|
treeDefaultExpandAll
|
|
|
|
onChange={onChange}
|
2022-09-19 11:00:17 +08:00
|
|
|
treeData={treeData}
|
|
|
|
/>
|
2021-03-08 18:06:49 +08:00
|
|
|
);
|
|
|
|
};
|
2015-12-28 19:16:02 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
export default App;
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|