Commit f07a59e 1 parent 71af666 commit f07a59e Copy full SHA for f07a59e
File tree 1 file changed +23
-2
lines changed
packages/components/tree/hooks
1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -55,11 +55,32 @@ export default function useTreeStore(state: TypeTreeState) {
55
55
56
56
const updateExpanded = ( ) => {
57
57
const { expandParent } = props ;
58
- if ( ! Array . isArray ( tExpanded . value ) ) return ;
58
+
59
+ const expandedValueSet = new Set < TreeNodeValue > ( ) ;
60
+
61
+ const getValueParentsToSet = ( values : TreeNodeValue [ ] ) => {
62
+ values . forEach ( ( val ) => {
63
+ const parents = store . getParents ( val ) ;
64
+ parents . forEach ( ( parent ) => {
65
+ expandedValueSet . add ( parent . value ) ;
66
+ } ) ;
67
+ } ) ;
68
+ } ;
69
+
70
+ if ( Array . isArray ( tValue . value ) ) {
71
+ getValueParentsToSet ( tValue . value ) ;
72
+ }
73
+
74
+ if ( Array . isArray ( tExpanded . value ) ) {
75
+ tExpanded . value . forEach ( ( value ) => expandedValueSet . add ( value ) ) ;
76
+ }
77
+
78
+ const expandedValue = Array . from ( expandedValueSet ) ;
79
+
59
80
// 初始化展开状态
60
81
// 校验是否自动展开父节点
61
82
const expandedMap = new Map ( ) ;
62
- tExpanded . value . forEach ( ( val ) => {
83
+ expandedValue . forEach ( ( val ) => {
63
84
expandedMap . set ( val , true ) ;
64
85
if ( expandParent ) {
65
86
const node = store . getNode ( val ) ;
You can’t perform that action at this time.
0 commit comments