File tree Expand file tree Collapse file tree 3 files changed +26
-4
lines changed Expand file tree Collapse file tree 3 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -237,7 +237,7 @@ export class TreeNode {
237
237
if ( this . isLeaf ( ) ) {
238
238
// initExpanded 时,子节点没有完全加载,无法依赖 isLeaf 状态判断
239
239
this . expanded = false ;
240
- tree . expandedMap . delete ( this . value ) ;
240
+ this . tree . expandedMap . delete ( this . value ) ;
241
241
}
242
242
243
243
// checked 状态依赖于子节点状态
@@ -323,6 +323,9 @@ export class TreeNode {
323
323
if ( list . length <= 0 ) {
324
324
return ;
325
325
}
326
+
327
+ const wasLeaf = this . isLeaf ( ) ;
328
+
326
329
if ( ! Array . isArray ( this . children ) ) {
327
330
this . children = [ ] ;
328
331
}
@@ -337,6 +340,13 @@ export class TreeNode {
337
340
children . push ( node ) ;
338
341
}
339
342
} ) ;
343
+
344
+ // 如果之前是叶子节点,现在有了子节点,且 expandAll 为 true,则展开
345
+ if ( wasLeaf && tree . config . expandAll && ! this . isLeaf ( ) ) {
346
+ tree . expandedMap . set ( this . value , true ) ;
347
+ this . expanded = true ;
348
+ }
349
+
340
350
tree . reflow ( this ) ;
341
351
this . updateRelated ( ) ;
342
352
}
@@ -867,8 +877,7 @@ export class TreeNode {
867
877
// 如果 valueMode 为 all、parentFirst,则视为选中
868
878
valueMode !== 'onlyLeaf'
869
879
// 如果 valueMode 为 onlyLeaf 并且当前节点是叶子节点,则视为选中
870
- || this . isLeaf ( )
871
- )
880
+ || this . isLeaf ( ) )
872
881
) {
873
882
return true ;
874
883
}
Original file line number Diff line number Diff line change @@ -234,7 +234,7 @@ export class TreeNode {
234
234
if ( this . isLeaf ( ) ) {
235
235
// initExpanded 时,子节点没有完全加载,无法依赖 isLeaf 状态判断
236
236
this . expanded = false ;
237
- tree . expandedMap . delete ( this . value ) ;
237
+ this . tree . expandedMap . delete ( this . value ) ;
238
238
}
239
239
240
240
// 节点的选中状态同时依赖于子节点状态与父节点状态
@@ -320,6 +320,9 @@ export class TreeNode {
320
320
if ( list . length <= 0 ) {
321
321
return ;
322
322
}
323
+
324
+ const wasLeaf = this . isLeaf ( ) ;
325
+
323
326
if ( ! Array . isArray ( this . children ) ) {
324
327
this . children = [ ] ;
325
328
}
@@ -334,6 +337,13 @@ export class TreeNode {
334
337
children . push ( node ) ;
335
338
}
336
339
} ) ;
340
+
341
+ // 如果之前是叶子节点,现在有了子节点,且 expandAll 为 true,则展开
342
+ if ( wasLeaf && tree . config . expandAll && ! this . isLeaf ( ) ) {
343
+ tree . expandedMap . set ( this . value , true ) ;
344
+ this . expanded = true ;
345
+ }
346
+
337
347
tree . reflow ( this ) ;
338
348
this . updateRelated ( ) ;
339
349
}
Original file line number Diff line number Diff line change @@ -631,6 +631,9 @@ describe('tree:append', () => {
631
631
} ]
632
632
} , {
633
633
value : 't2' ,
634
+ children : [ {
635
+ value : 't2.1' ,
636
+ } ]
634
637
} ] ) ;
635
638
await delay ( 0 ) ;
636
639
tree . setExpanded ( [ 't1' , 't2' ] ) ;
You can’t perform that action at this time.
0 commit comments