@@ -144,15 +144,18 @@ label: {
144
144
},
145
145
```
146
146
147
- ## index
147
+ ## reduce
148
148
149
- Tells vue-select what key to use when generating option
150
- values when each ` option ` is an object.
149
+ When working with objects, the reduce
150
+ prop allows you to transform a given
151
+ object to only the information you
152
+ want passed to a v-model binding
153
+ or @input event.
151
154
152
155
``` js
153
- index : {
154
- type: String ,
155
- default: null
156
+ reduce : {
157
+ type: Function ,
158
+ default : option => option,
156
159
},
157
160
```
158
161
@@ -168,24 +171,20 @@ display, you should use the `option` and
168
171
169
172
``` js
170
173
getOptionLabel: {
171
- type: Function ,
172
- default (option ) {
173
- if (this .index ) {
174
- option = this .findOptionByIndexValue (option);
175
- }
176
-
177
- if (typeof option === " object" ) {
178
- if (! option .hasOwnProperty (this .label )) {
179
- return console .warn (
180
- ` [vue-select warn]: Label key "option.${ this .label } " does not` +
181
- ` exist in options object ${ JSON .stringify (option)} .\n ` +
182
- " http://sagalbot.github.io/vue-select/#ex-labels"
183
- );
184
- }
185
- return option[this .label ];
186
- }
187
- return option;
188
- }
174
+ type: Function ,
175
+ default (option ) {
176
+ if (typeof option === ' object' ) {
177
+ if (! option .hasOwnProperty (this .label )) {
178
+ return console .warn (
179
+ ` [vue-select warn]: Label key "option.${ this .label } " does not` +
180
+ ` exist in options object ${ JSON .stringify (option)} .\n ` +
181
+ ' http://sagalbot.github.io/vue-select/#ex-labels'
182
+ )
183
+ }
184
+ return option[this .label ]
185
+ }
186
+ return option;
187
+ }
189
188
},
190
189
```
191
190
@@ -294,14 +293,15 @@ User defined function for adding Options
294
293
295
294
``` js
296
295
createOption: {
297
- type: Function ,
298
- default (newOption ) {
299
- if (typeof this .optionList [0 ] === " object" ) {
300
- newOption = { [this .label ]: newOption };
301
- }
302
- this .$emit (" option:created" , newOption);
303
- return newOption;
304
- }
296
+ type: Function ,
297
+ default (newOption ) {
298
+ if (typeof this .optionList [0 ] === ' object' ) {
299
+ newOption = {[this .label ]: newOption}
300
+ }
301
+
302
+ this .$emit (' option:created' , newOption)
303
+ return newOption
304
+ }
305
305
},
306
306
```
307
307
0 commit comments