0

Can you use vue-select to reduce a value to an object with specific properties?

I am trying to do something like this:

<v-select 
        multiple 
        :options="locations_ordered" 
        v-model="state.modal.data.locations" 
        label="name" 
        :reduce="loc => {id: loc.id, name: loc.name}"
        >

But it's throwing an error at the first colon. What's the right syntax here?

Page Russell
  • 1
  • 1
  • 1

1 Answers1

2

According to Vue docs transforming selections, you use reduce to select to a single key.

In your example, you'd be able to reduce to just returning the id(or name). See below:

<v-select multiple
          :options="locations_ordered"
          v-model="state.modal.data.locations"
          label="name"
          :reduce="loc => loc.id">
</v-select>

If you want to reduce to a smaller class perhaps it would be better to run a .map() on the list before handing it to the vue-select control.

devtoka
  • 411
  • 3
  • 13
  • @Page Rusell if the answer was helpful please upvote, if not then please down vote, perhaps with some feedback. If the answer solved your issue please mark it as the accepted answer. Much appreciated – devtoka May 30 '20 at 21:37