2016-03-31 09:40:55 +08:00
|
|
|
---
|
2017-08-21 18:07:39 +08:00
|
|
|
order: 2
|
2016-08-05 11:47:31 +08:00
|
|
|
title:
|
|
|
|
zh-CN: 从数据直接生成
|
2018-06-30 14:59:55 +08:00
|
|
|
en-US: Generate from tree data
|
2016-03-31 09:40:55 +08:00
|
|
|
---
|
2016-02-01 17:06:54 +08:00
|
|
|
|
2016-08-05 11:47:31 +08:00
|
|
|
## zh-CN
|
|
|
|
|
2016-02-01 17:06:54 +08:00
|
|
|
使用 `treeData` 把 JSON 数据直接生成树结构。
|
|
|
|
|
2016-08-05 11:47:31 +08:00
|
|
|
## en-US
|
|
|
|
|
|
|
|
The tree structure can be populated using `treeData` property. This is a quick and easy way to provide the tree content.
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
2016-02-01 17:06:54 +08:00
|
|
|
import { TreeSelect } from 'antd';
|
2022-05-23 14:37:16 +08:00
|
|
|
import React, { useState } from 'react';
|
2016-02-01 17:06:54 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
const treeData = [
|
|
|
|
{
|
|
|
|
title: 'Node1',
|
|
|
|
value: '0-0',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
title: 'Child Node1',
|
|
|
|
value: '0-0-1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Child Node2',
|
|
|
|
value: '0-0-2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Node2',
|
|
|
|
value: '0-1',
|
|
|
|
},
|
|
|
|
];
|
2016-02-01 17:06:54 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => {
|
|
|
|
const [value, setValue] = useState<string>();
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const onChange = (newValue: string) => {
|
|
|
|
console.log(newValue);
|
|
|
|
setValue(newValue);
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
return (
|
|
|
|
<TreeSelect
|
|
|
|
style={{ width: '100%' }}
|
|
|
|
value={value}
|
|
|
|
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
|
|
|
treeData={treeData}
|
|
|
|
placeholder="Please select"
|
|
|
|
treeDefaultExpandAll
|
|
|
|
onChange={onChange}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default App;
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|