@@ -63,25 +63,28 @@ const TreeSelect = {
63
63
onChange ( ) {
64
64
this . $emit ( 'change' , ...arguments ) ;
65
65
} ,
66
- updateTreeData ( list = [ ] ) {
67
- for ( let i = 0 , len = list . length ; i < len ; i ++ ) {
68
- const { label , title , scopedSlots = { } , children } = list [ i ] ;
69
- const { $ scopedSlots } = this ;
66
+ updateTreeData ( treeData ) {
67
+ const { $scopedSlots } = this ;
68
+ return treeData . map ( item => {
69
+ const { label , title , scopedSlots = { } , children } = item ;
70
70
let newLabel = typeof label === 'function' ? label ( this . $createElement ) : label ;
71
71
let newTitle = typeof title === 'function' ? title ( this . $createElement ) : title ;
72
72
if ( ! newLabel && scopedSlots . label && $scopedSlots [ scopedSlots . label ] ) {
73
- newLabel = $scopedSlots . label ( list [ i ] ) ;
73
+ newLabel = $scopedSlots . label ( item ) ;
74
74
}
75
75
if ( ! newTitle && scopedSlots . title && $scopedSlots [ scopedSlots . title ] ) {
76
- newTitle = $scopedSlots . title ( list [ i ] ) ;
76
+ newTitle = $scopedSlots . title ( item ) ;
77
77
}
78
- const item = {
79
- // label: newLabel ,
78
+ const treeNodeProps = {
79
+ ... item ,
80
80
title : newTitle || newLabel ,
81
+ dataRef : item ,
81
82
} ;
82
- this . updateTreeData ( children || [ ] ) ;
83
- Object . assign ( list [ i ] , item ) ;
84
- }
83
+ if ( children ) {
84
+ return { ...treeNodeProps , children : this . updateTreeData ( children ) } ;
85
+ }
86
+ return treeNodeProps ;
87
+ } ) ;
85
88
} ,
86
89
renderTreeSelect ( locale ) {
87
90
const props = getOptionProps ( this ) ;
@@ -105,7 +108,10 @@ const TreeSelect = {
105
108
] ) ;
106
109
let suffixIcon = getComponentFromProp ( this , 'suffixIcon' ) ;
107
110
suffixIcon = Array . isArray ( suffixIcon ) ? suffixIcon [ 0 ] : suffixIcon ;
108
- this . updateTreeData ( props . treeData || [ ] ) ;
111
+ let treeData = props . treeData ;
112
+ if ( treeData ) {
113
+ treeData = this . updateTreeData ( treeData ) ;
114
+ }
109
115
const cls = {
110
116
[ `${ prefixCls } -lg` ] : size === 'large' ,
111
117
[ `${ prefixCls } -sm` ] : size === 'small' ,
@@ -128,20 +134,23 @@ const TreeSelect = {
128
134
) ;
129
135
130
136
const VcTreeSelectProps = {
131
- props : {
132
- switcherIcon : this . renderSwitcherIcon ,
133
- inputIcon,
134
- removeIcon,
135
- clearIcon,
136
- ...rest ,
137
- getPopupContainer : getPopupContainer || getContextPopupContainer ,
138
- dropdownClassName : classNames ( dropdownClassName , `${ prefixCls } -tree-dropdown` ) ,
139
- prefixCls,
140
- dropdownStyle : { maxHeight : '100vh' , overflow : 'auto' , ...dropdownStyle } ,
141
- treeCheckable : checkable ,
142
- notFoundContent : notFoundContent || locale . notFoundContent ,
143
- __propsSymbol__ : Symbol ( ) ,
144
- } ,
137
+ props : Object . assign (
138
+ {
139
+ switcherIcon : this . renderSwitcherIcon ,
140
+ inputIcon,
141
+ removeIcon,
142
+ clearIcon,
143
+ ...rest ,
144
+ getPopupContainer : getPopupContainer || getContextPopupContainer ,
145
+ dropdownClassName : classNames ( dropdownClassName , `${ prefixCls } -tree-dropdown` ) ,
146
+ prefixCls,
147
+ dropdownStyle : { maxHeight : '100vh' , overflow : 'auto' , ...dropdownStyle } ,
148
+ treeCheckable : checkable ,
149
+ notFoundContent : notFoundContent || locale . notFoundContent ,
150
+ __propsSymbol__ : Symbol ( ) ,
151
+ } ,
152
+ treeData ? { treeData } : { } ,
153
+ ) ,
145
154
class : cls ,
146
155
on : { ...this . $listeners , change : this . onChange } ,
147
156
ref : 'vcTreeSelect' ,
0 commit comments