@@ -63,25 +63,28 @@ const TreeSelect = {
6363 onChange ( ) {
6464 this . $emit ( 'change' , ...arguments ) ;
6565 } ,
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 ;
7070 let newLabel = typeof label === 'function' ? label ( this . $createElement ) : label ;
7171 let newTitle = typeof title === 'function' ? title ( this . $createElement ) : title ;
7272 if ( ! newLabel && scopedSlots . label && $scopedSlots [ scopedSlots . label ] ) {
73- newLabel = $scopedSlots . label ( list [ i ] ) ;
73+ newLabel = $scopedSlots . label ( item ) ;
7474 }
7575 if ( ! newTitle && scopedSlots . title && $scopedSlots [ scopedSlots . title ] ) {
76- newTitle = $scopedSlots . title ( list [ i ] ) ;
76+ newTitle = $scopedSlots . title ( item ) ;
7777 }
78- const item = {
79- // label: newLabel ,
78+ const treeNodeProps = {
79+ ... item ,
8080 title : newTitle || newLabel ,
81+ dataRef : item ,
8182 } ;
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+ } ) ;
8588 } ,
8689 renderTreeSelect ( locale ) {
8790 const props = getOptionProps ( this ) ;
@@ -105,7 +108,10 @@ const TreeSelect = {
105108 ] ) ;
106109 let suffixIcon = getComponentFromProp ( this , 'suffixIcon' ) ;
107110 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+ }
109115 const cls = {
110116 [ `${ prefixCls } -lg` ] : size === 'large' ,
111117 [ `${ prefixCls } -sm` ] : size === 'small' ,
@@ -128,20 +134,23 @@ const TreeSelect = {
128134 ) ;
129135
130136 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+ ) ,
145154 class : cls ,
146155 on : { ...this . $listeners , change : this . onChange } ,
147156 ref : 'vcTreeSelect' ,
0 commit comments