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

84 lines
1.3 KiB
Markdown
Raw Normal View History

2016-03-31 09:40:55 +08:00
---
2017-08-21 18:07:39 +08:00
order: 3
2016-08-05 11:47:31 +08:00
title:
2017-08-21 18:07:39 +08:00
zh-CN: 可勾选
en-US: Checkable
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
2017-08-21 18:07:39 +08:00
使用勾选框实现多选功能。
2015-12-28 19:16:02 +08:00
2016-08-05 11:47:31 +08:00
## en-US
Multiple and checkable.
```tsx
2015-12-28 19:16:02 +08:00
import { TreeSelect } from 'antd';
2022-05-21 22:14:15 +08:00
import React, { useState } from 'react';
2018-06-27 15:55:04 +08:00
2019-06-19 19:09:08 +08:00
const { SHOW_PARENT } = TreeSelect;
2015-12-28 19:16:02 +08:00
2019-05-07 14:57:32 +08:00
const treeData = [
{
title: 'Node1',
value: '0-0',
key: '0-0',
children: [
{
title: 'Child Node1',
value: '0-0-0',
key: '0-0-0',
},
],
},
{
title: 'Node2',
value: '0-1',
key: '0-1',
children: [
{
title: 'Child Node3',
value: '0-1-0',
key: '0-1-0',
},
{
title: 'Child Node4',
value: '0-1-1',
key: '0-1-1',
},
{
title: 'Child Node5',
value: '0-1-2',
key: '0-1-2',
},
],
},
];
2015-12-28 19:16:02 +08:00
const App: React.FC = () => {
const [value, setValue] = useState(['0-0-0']);
2018-06-27 15:55:04 +08:00
const onChange = (newValue: string[]) => {
2018-06-23 16:35:42 +08:00
console.log('onChange ', value);
setValue(newValue);
2019-05-07 14:57:32 +08:00
};
2018-06-27 15:55:04 +08:00
const tProps = {
treeData,
value,
onChange,
treeCheckable: true,
showCheckedStrategy: SHOW_PARENT,
placeholder: 'Please select',
style: {
width: '100%',
},
};
return <TreeSelect {...tProps} />;
};
2015-12-28 19:16:02 +08:00
export default App;
2019-05-07 14:57:32 +08:00
```