@@ -42,17 +42,6 @@ export default class PickerItem extends SuperComponent {
4242 relations : RelationsOptions = {
4343 '../picker/picker' : {
4444 type : 'parent' ,
45- linked ( parent ) {
46- if ( 'keys' in parent . data ) {
47- const { keys } = parent . data ;
48-
49- if ( keys === null || JSON . stringify ( this . data . pickerKeys ) === JSON . stringify ( keys ) ) return ;
50-
51- this . setData ( {
52- pickerKeys : { ...this . data . pickerKeys , ...keys } ,
53- } ) ;
54- }
55- } ,
5645 } ,
5746 } ;
5847
@@ -65,7 +54,7 @@ export default class PickerItem extends SuperComponent {
6554 properties = props ;
6655
6756 observers = {
68- 'options, pickerKeys ' ( ) {
57+ 'options, keys ' ( ) {
6958 this . update ( ) ;
7059 } ,
7160 } ;
@@ -78,7 +67,7 @@ export default class PickerItem extends SuperComponent {
7867 value : '' ,
7968 curIndex : 0 ,
8069 columnIndex : 0 ,
81- pickerKeys : { value : 'value' , label : 'label' , icon : 'icon' } ,
70+ keys : { } ,
8271 formatOptions : props . options . value ,
8372 // 虚拟滚动相关
8473 enableVirtualScroll : false , // 是否启用虚拟滚动
@@ -283,10 +272,10 @@ export default class PickerItem extends SuperComponent {
283272 } ,
284273
285274 updateSelected ( index : number , trigger : boolean ) {
286- const { columnIndex, pickerKeys , formatOptions } = this . data ;
275+ const { columnIndex, keys , formatOptions } = this . data ;
287276 this . _selectedIndex = index ;
288- this . _selectedValue = formatOptions [ index ] ?. [ pickerKeys ?. value ] ;
289- this . _selectedLabel = formatOptions [ index ] ?. [ pickerKeys ?. label ] ;
277+ this . _selectedValue = formatOptions [ index ] ?. [ keys ?. value ] ;
278+ this . _selectedLabel = formatOptions [ index ] ?. [ keys ?. label ] ;
290279
291280 if ( trigger ) {
292281 this . $parent ?. triggerColumnChange ( {
@@ -298,7 +287,7 @@ export default class PickerItem extends SuperComponent {
298287
299288 // 刷新选中状态
300289 update ( ) {
301- const { options, value, pickerKeys , format, columnIndex, itemHeight, visibleItemCount } = this . data ;
290+ const { options, value, keys , format, columnIndex, itemHeight, visibleItemCount } = this . data ;
302291
303292 const formatOptions = this . formatOption ( options , columnIndex , format ) ;
304293 const optionsCount = formatOptions . length ;
@@ -310,10 +299,10 @@ export default class PickerItem extends SuperComponent {
310299 let index : number = - 1 ;
311300 if ( optionsCount > 500 ) {
312301 // 构建临时 Map(只在查找时构建,不缓存)
313- const valueMap = new Map < any , number > ( formatOptions . map ( ( item , idx ) => [ item [ pickerKeys ?. value ] , idx ] ) ) ;
302+ const valueMap = new Map < any , number > ( formatOptions . map ( ( item , idx ) => [ item [ keys ?. value ] , idx ] ) ) ;
314303 index = valueMap . get ( value ) ?? - 1 ;
315304 } else {
316- index = formatOptions . findIndex ( ( item : PickerItemOption ) => item [ pickerKeys ?. value ] === value ) ;
305+ index = formatOptions . findIndex ( ( item : PickerItemOption ) => item [ keys ?. value ] === value ) ;
317306 }
318307 const selectedIndex = index > 0 ? index : 0 ;
319308
@@ -410,13 +399,13 @@ export default class PickerItem extends SuperComponent {
410399 } ,
411400
412401 getCurrentSelected ( ) {
413- const { offset, itemHeight, formatOptions, pickerKeys } = this . data ;
402+ const { offset, itemHeight, formatOptions, keys } = this . data ;
414403 const currentIndex = Math . max ( 0 , Math . min ( Math . round ( - offset / itemHeight ) , this . getCount ( ) - 1 ) ) ;
415404
416405 return {
417406 index : currentIndex ,
418- value : formatOptions [ currentIndex ] ?. [ pickerKeys ?. value ] ,
419- label : formatOptions [ currentIndex ] ?. [ pickerKeys ?. label ] ,
407+ value : formatOptions [ currentIndex ] ?. [ keys ?. value ] ,
408+ label : formatOptions [ currentIndex ] ?. [ keys ?. label ] ,
420409 } ;
421410 } ,
422411 } ;
0 commit comments