-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ff8029
commit 3c6f83d
Showing
4 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ class App extends React.Component { | |
'表格', | ||
'表单', | ||
'级联树', | ||
'树选择', | ||
'二级菜单', | ||
'二级菜单-1', | ||
'三级菜单', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React, { useState } from 'react' | ||
import { TreeSelect } from 'antd' | ||
|
||
// export default class TreeSelectDemo extends React.Component { | ||
|
||
// } | ||
const initTreeData = [ | ||
{ id: 1, pId: 0, value: '1', title: 'Expand to load', selectable: false }, | ||
{ id: 2, pId: 0, value: '2', title: 'Expand to load' }, | ||
{ id: 3, pId: 0, value: '3', title: 'Tree Node', isLeaf: true } | ||
] | ||
|
||
function TreeSelectDemo() { | ||
const [treeValue, setTreeValue] = useState(undefined) | ||
const [treeData, setTreeData] = useState(initTreeData) | ||
|
||
function getTreeNode(parentId, isLeaf) { | ||
const random = Math.random() | ||
.toString(36) | ||
.substring(2, 6) | ||
return { | ||
id: random, | ||
pId: parentId, | ||
value: random, | ||
title: isLeaf ? 'Tree Node' : 'Expand to load', | ||
isLeaf, | ||
selectable: isLeaf | ||
} | ||
} | ||
|
||
function handeChange(value) { | ||
setTreeValue(value) | ||
} | ||
|
||
function onLoadData(treeNode) { | ||
return new Promise(resolve => { | ||
const { id } = treeNode.props | ||
const arr = treeData.concat([ | ||
getTreeNode(id, false), | ||
getTreeNode(id, true) | ||
]) | ||
setTreeData(arr) | ||
resolve() | ||
}) | ||
} | ||
|
||
return ( | ||
<div style={{ | ||
width: '220px' | ||
}}> | ||
<TreeSelect | ||
treeDataSimpleMode | ||
style={{ width: '100%' }} | ||
value={treeValue} | ||
dropdownMenuStyle={{ maxHeight: 400, overflow: 'auto' }} | ||
placeholder={'请选择'} | ||
onChange={handeChange} | ||
loadData={onLoadData} | ||
treeData={treeData} | ||
></TreeSelect> | ||
</div> | ||
) | ||
} | ||
|
||
export default TreeSelectDemo |