File tree Expand file tree Collapse file tree 1 file changed +29
-2
lines changed Expand file tree Collapse file tree 1 file changed +29
-2
lines changed Original file line number Diff line number Diff line change 499
499
default: ' label'
500
500
},
501
501
502
+ /**
503
+ * Tells vue-select what key to use when generating option
504
+ * values when each `option` is an object.
505
+ * @type {String}
506
+ */
507
+ index: {
508
+ type: String ,
509
+ default: null
510
+ },
511
+
502
512
/**
503
513
* Callback to generate the label text. If {option}
504
514
* is an object, returns option[this.label] by default.
521
531
return option[this .label ]
522
532
}
523
533
}
534
+ if (this .index ) {
535
+ let label = option
536
+ this .options .forEach ((val ) => {
537
+ if (val[this .index ] == option) {
538
+ label = val[this .label ]
539
+ }
540
+ })
541
+ return label
542
+ }
524
543
return option;
525
544
}
526
545
},
765
784
if (this .taggable && ! this .optionExists (option)) {
766
785
option = this .createOption (option)
767
786
}
768
-
787
+ if (this .index ) {
788
+ if (! option .hasOwnProperty (this .index )) {
789
+ console .warn (
790
+ ` [vue-select warn]: Index key "option.${ this .index } " does not` +
791
+ ` exist in options object ${ JSON .stringify (option)} .\n ` ;
792
+ )
793
+ }
794
+ option = option[this .index ]
795
+ }
769
796
if (this .multiple && ! this .mutableValue ) {
770
797
this .mutableValue = [option]
771
798
} else if (this .multiple ) {
787
814
if (this .multiple ) {
788
815
let ref = - 1
789
816
this .mutableValue .forEach ((val ) => {
790
- if (val === option || typeof val === ' object' && val[this .label ] === option[this .label ]) {
817
+ if (val === option || ( this . index && val === option[ this . index ]) || ( typeof val === ' object' && val[this .label ] === option[this .label ]) ) {
791
818
ref = val
792
819
}
793
820
})
You can’t perform that action at this time.
0 commit comments