ant-design/components/tree-select/demo/basic.md

76 lines
1.3 KiB
Markdown
Raw Normal View History

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.
```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
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>,
},
],
},
],
},
];
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
};
return (
<TreeSelect
showSearch
style={{ width: '100%' }}
value={value}
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
placeholder="Please select"
allowClear
treeDefaultExpandAll
onChange={onChange}
treeData={treeData}
/>
);
};
2015-12-28 19:16:02 +08:00
export default App;
2019-05-07 14:57:32 +08:00
```