Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vuejs Vuetify how to access properties of object in v-select

My use case.

  1. I got an array of objects from a back-end api.
  2. I want to render those objects in a v-select

This is my code.

<v-select   :items="categories"   name="category"   label="Select a category"   v-model="category"   v-validate="'required'"> </v-select> 

But it gives me the output.

enter image description here

But I wants objects name property to be display in the v-select

We would do this in vanilla Vue.js

<li v-for="cat in categories" :key="cat.name">{{cat.name}}</li> 

But here with vuetify we can't do this.

:items="categories.name" 

Vuetify documentation

Can be an array of objects or array of strings. When using objects, will look for a text and value field. This can be changed using the item-text and item-value props.

What they actually mean by item-text and item-value How do I achieve this using item-text

like image 890
Pathum Kalhan Avatar asked Jul 12 '18 03:07

Pathum Kalhan


People also ask

What is reduce in V-select?

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>

What is V layout in Vuetify?

There are 2 primary layout components in Vuetify, v-app and v-main . The v-app component is the root of your application and a direct replacement for the default Vue entrypoint, <div id="app"> . The v-main component is a semantic replacement for the main HTML element and the root of your application's content.


1 Answers

Your category has name attribute, you can pass to item-text:

    <v-select       :items="categories"       v-model="category"       name="category"       v-validate="'required'"       item-text="name"       label="Select a category"       /> 
like image 133
ittus Avatar answered Sep 28 '22 07:09

ittus