What is the best way to show customized text from a data member within the :items object array for the item title in a v-select (Vuetify) dropdown menu

Currently, I am new to Vue and exploring Vuetify while working on building a dropdown using "v-select".

If there is a simpler way to achieve this, it would be awesome! Otherwise, my plan is to create a new array, convert data for certain members into objects, copy them to the new array, and then set that array as :items in v-select.

Below is my code snippet:

<v-select 
    label="Select a permission to copy"
    variant="underlined"
    item-title="resource"
    no-data-text="No permission to choose from"
    :items="permissionsToCopy"
    v-model="selectedPermissionToCopy"
    return-object
>
</v-select>

For resource in item-title, I aim to display it like - if it is resource == company_user_licence then I want the item-title to show as Licence Permission: User.

I have been searching for ways to customize the template for item-title, but so far I have only found methods for item-text and item-value, not item-title.

If you need further clarification or more details, please don't hesitate to ask. Thank you!

Answer №1

To customize the item-title using the v-list-item component, you can follow this example:

<template>
    <v-select label="User" :items="items" item-title="name">
        <template v-slot:item="{ props, item }">
            <v-list-item
                v-bind="props"
                :title="`${item.title} - ${item.value}`"
            ></v-list-item>
        </template>
    </v-select>
</template>

<script>
    export default {
        data: () => ({
            items: [
                {
                    name: 'John',
                    department: 'Marketing',
                },
                {
                    name: 'Jane',
                    department: 'Engineering',
                },
                {
                    name: 'Joe',
                    department: 'Sales',
                },
                {
                    name: 'Janet',
                    department: 'Engineering',
                },
                {
                    name: 'Jake',
                    department: 'Marketing',
                },
                {
                    name: 'Jack',
                    department: 'Sales',
                },
            ],
        }),
    }
    </script>

If you need to implement more complex logic for the title, you can use a method like this: :title='myCustomTitle()'.

Answer №2

Here is my solution that I came up with.

In addition to @Mojtaba's answer, I had to include vslot:selection for it to display my selected item correctly. Thank you for the help!

I'm documenting this here in case someone else is looking for similar solutions.

<v-select 
    label="Select a permission to copy"
    variant="underlined"
    no-data-text="No permission to choose from"
    :items="permissionsToCopy"
    v-model="selectedPermissionToCopy"
    return-object
>
    <template v-slot:selection="{item, props}">
        <v-list-item v-bind="props" style="padding: 0;" :title="convertToReadableText(item.value)"></v-list-item>
    </template>
    <template v-slot:item="{item, props}">
        <v-list-item v-bind="props" :title="convertToReadableText(item.value)"></v-list-item>
    </template>
</v-select>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Acquiring the item by referencing one of its property's values

Imagine you have a JSON structure that looks like this: [ { "name":"Foo" "nickname":"Lorem Ipsum" }, { "name":"Bar" "nickname":"Dolor S ...

Changing the color of a progress bar in Bootstrap based on a specific percentage level

var elem = document.getElementById("progress-bar"); var progress = 75; elem.style.width = 80 + '%'; if (progress > 80) { elem.style.background = "red"; } #myProgress { height: 5px; } #progress-bar { w ...

How do I automatically redirect to a different URL after verifying that the user has entered certain words using Javascript?

I want to create a function where if a user input on the "comments" id matches any word in my FilterWord's array, they will be redirected to one URL. If the input does not match, they will be redirected to another URL. The checking process should onl ...

Utilizing Ajax: Sending Customized Data to a Modal

Having never worked with jquery before, I struggled to find a solution for my specific case. On the cockpit.php page, I have a form that retrieves content from a mysql database. Currently, I am able to display this content in a div on the same cockpit.php ...

Children components in Vue.js are receiving an undefined props object

Within my application, I am working with a parent and child component. The parent component directly includes the child component, which needs to access data from the parent. This data is fetched from a REST API within the parent component. However, when t ...

Tips for keeping a specific key value pair as the final entry in a Typescript Object

My goal is to construct a Typescript Object that has a specific element with the key 'NONE' always positioned at the end. This arrangement is crucial for displaying the object in my HTML page with this value appearing last. I am seeking an implem ...

Showcasing the time variance using javascript/jquery

I am currently using a datepicker to select dates, with the intention of calculating the difference between the chosen dates and then displaying an alert with the calculated difference. Unfortunately, I am encountering issues with getting the code to work ...

Verify the presence of a specific value within an array of objects in JavaScript that was retrieved from an AJAX response, and then

I am encountering an issue with the code below where I am unable to filter entry.AllLinks. The code snippet is shown here: $.ajax({ url: url, type: "get", headers: {"Accept": "application/json;odata=verbose"}, success: function (data) { ...

Indicate the end of the row in JavaScript when using the match() function

What's the best way to identify the end of a row when using the match() function? I'm trying to extract "2021 JANUARY 18 MONDAY" from this page. If there is additional text after the desired string, I typically use this code: var content = UrlFe ...

Exploring the process of utilizing CodeMirror within Vue.js to transmit specific line numbers

I am trying to incorporate Codemirror into my Vue.js project in order to have two text areas. The goal is for selecting specific lines of code in one area to automatically highlight the corresponding lines in the other area. https://i.stack.imgur.com/UDYv ...

Having difficulty displaying elements from two arrays at particular intervals

I am currently working with two arrays that have the same number of items in each. My goal is to print these items in intervals within the console. The desired output would look something like this: 1 Bruce Wayne 45 Then, after a one-second interval, it s ...

Looking for consistent vertical and horizontal scrolling behavior in a React project

I am in need of assistance as I lack the necessary expertise in ReactJs to transform this design. Currently, it is written in Jquery but I would like guidance on how to recreate it in ReactJs. Specifically, I want the left div with the topic for each row t ...

Previewing an uploaded image before submitting with FileBase64: A step-by-step guide

How can I implement a preview for an uploaded image before submitting the form? I have the upload functionality working but I would like to add a preview feature for the image. Below is the code snippet I am currently using: const [shop, setShop] = us ...

calculation of progress bar advancement

I want to make the progress bar in my game responsive to changes in the winning score. Currently, it moves from 0% to 100%, which is equivalent to 100 points - the default winning score. But I need the progress bar to adjust accordingly based on the user-i ...

employing ajax for handling a form

Currently, I am facing an issue with updating a user's email on a page. The div refreshes upon submission as intended, but the database is not being updated, and I can't figure out why. My layout consists of a single page where clicking a menu l ...

Run some code and then enter interactive mode

Is there a method to run certain code (from a file or a string) before entering interactive mode in node.js? For instance, if I have script called __preamble__.js with the following content: console.log("preamble executed! poor guy!"); and a user enters ...

Playing sound files on Angular using Howler.JS

I am currently trying to incorporate the ability to play an mp3 file within a Cordova + Ionic hybrid app. The sound file is located at: www/sounds/dubstep/sound.mp3 I am attempting to play the file from a service placed in /www/scripts/services/global.j ...

Identify the browser dimensions and implement CSS styling for all screen resolutions

I am currently facing an issue with a function that I have created to apply CSS changes to a menu based on browser resizing and different resolutions. The problem lies in the fact that my function does not seem to be correctly interpreted by the browser. W ...

Retrieve a specific object from a JSON array nested within an array of objects, by utilizing a PHP script

There are two JSON files that contain JSON objects, with one of the files containing an array of objects within another array of objects. The first file is orders.json: { "orders": [ { "address": null, ...