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.
|
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
```jsx
|
2021-03-09 14:45:54 +08:00
|
|
|
import React, { useState } from 'react';
|
2015-12-28 19:16:02 +08:00
|
|
|
import { TreeSelect } from 'antd';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2019-06-19 19:09:08 +08:00
|
|
|
const { TreeNode } = TreeSelect;
|
2015-12-28 19:16:02 +08:00
|
|
|
|
2021-03-08 18:06:49 +08:00
|
|
|
const Demo = () => {
|
|
|
|
const [value, setValue] = useState(undefined);
|
|
|
|
const onChange = () => {
|
|
|
|
setValue(value);
|
2019-05-07 14:57:32 +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}
|
|
|
|
>
|
|
|
|
<TreeNode value="parent 1" title="parent 1">
|
|
|
|
<TreeNode value="parent 1-0" title="parent 1-0">
|
|
|
|
<TreeNode value="leaf1" title="leaf1" />
|
|
|
|
<TreeNode value="leaf2" title="leaf2" />
|
|
|
|
</TreeNode>
|
|
|
|
<TreeNode value="parent 1-1" title="parent 1-1">
|
|
|
|
<TreeNode value="leaf3" title={<b style={{ color: '#08c' }}>leaf3</b>} />
|
2016-01-21 17:14:39 +08:00
|
|
|
</TreeNode>
|
2021-03-08 18:06:49 +08:00
|
|
|
</TreeNode>
|
|
|
|
</TreeSelect>
|
|
|
|
);
|
|
|
|
};
|
2015-12-28 19:16:02 +08:00
|
|
|
|
2022-04-03 23:27:45 +08:00
|
|
|
export default () => <Demo />;
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|