When utilizing Vuetify's v-for directive, each list item will reveal its menu upon being clicked

How can I make each item in my Vuetify list open a menu individually on click, instead of opening all menus at once when any item is selected?


    <v-list-item-group>
      <RecycleScroller
        v-if="drive_stop_info.drive_stop_list.length > 0"
        v-slot="{ item }"
        class="scroller"
        :items="history_list"
        :item-size="50"
        key-field="_index"
      >
        <v-list-item
          class="py-0 px-2"
          dense
          flat
          selectable>

          <v-menu
            v-model = "zone_list_visible"
            no-ripple
            :close-on-content-click="true"
            >
              <template v-slot:activator="{ on, attrs }">
                <v-avatar
                  @click="zoneListVisible(item)"
                  v-if="getZoneArray(item).length>2"
                  v-bind="attrs"
                  v-on="on"
                  color="grey lighten-2"
                  size="30"
                  class="grey--text">
                  +{{getZoneArray(item).length-2}}
                </v-avatar>
              </template>
              <v-list dense>
                <v-list-item
                  v-for="(zone, i) in getZoneArray(item)"
                  :key="i"
                  @click="panMapToZone(zone.zone_id)"
                  >
                  <v-chip :color="zone.detail.hex_color"> {{ zone.display_name }}</v-chip>
                </v-list-item>
              </v-list>
            </v-menu>
         </v-list-item>
      </RecycleScroller>
    </v-list-item-group>

data:


data() {
    return {
      zone_list_visible: false,
      menu_item: undefined,
    },

in methods:


zoneListVisible(item){
      this.zone_list_visible = true;
      this.menuItem = item;
    },

Answer №1

It seems like there is a missing piece of code that would provide a clearer understanding, but it appears that the issue lies in checking the same variable for all items, leading them to always be true or false.

A possible solution could involve creating a child component for each item, each with its own is_visible variable. When the child component is clicked, it can be set to true, allowing the menu to open. Additionally, if you are performing some action on the item after it is clicked, consider emitting an event to the parent component along with the item itself.

Additionally, a small inconsistency exists where the data includes menu_item as snake_case, while the methods use camelcase as menuItem. It's unclear if these refer to the same variable.

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

Empty dropdown list displaying no options

<script> function populateDropdown() { var dropdown = document.getElementById("ddFAge"); for(var i=1;i<=100;i++) { var newOption = new Option() newOption=document.createEle ...

The logical OR operator in JavaScript (denoted as ||)

Can anyone explain the functionality of this operator in JavaScript? I have come across this operator in two different contexts: //context 1 function(e){ e = e || window.event; //context 2 if(a || b) In C or C++, I understand that the return value of th ...

Issues with Angular ngroute: controllers are not functioning properly

In order to route my application with different themes on the same page, I plan to utilize the ngroute module. Here's an example of how I intend to achieve this: <html> <head> <title>Angular JS Views</title> ...

Adjusting the size or compressing images during the upload process to Firebase

I have a Google Cloud function that successfully uploads images, but I want to add functionality to compress the image in order to prevent excessive charges for uploading large files. Any suggestions on how to achieve this would be highly appreciated! He ...

Show parent menu when child menu is clicked

I'm dealing with a menu that has sub-child menus, and the issue I'm encountering is that whenever I choose a child menu after the page loads, the menu collapses. My goal is to have the parent menu open and expanded instead. This is the HTML Code ...

Converting Javascript tools into Typescript

I'm currently in the process of migrating my Ionic1 project to Ionic2, and it's been quite an interesting journey so far! One challenge that I'm facing is how to transfer a lengthy list of utility functions written in JavaScript, like CmToFe ...

What is the best way to form a singular entity and insert numerous sets of key-value pairs within it?

Currently, I am working on creating an object that contains multiple key-pair values obtained from an API response. My goal is to transform the API response into a single object, but the code I have written does not produce the desired result. This is my ...

Hiding icons in a jquery datatable's table

I am currently developing an inline editing feature, and I would like to display a green checkmark in a column cell to indicate that the record has been updated. However, I need to hide it initially. This is how it looks at the moment: https://i.sstatic. ...

Creating dynamic div shapes in HTML is a fun and creative way

Is it possible to create a div with a unique shape? I know that by default, divs are rectangular and you can achieve some shapes using the border-radius property, but what I really want is a semi-leaf shaped element. Something like this: The image might n ...

What is the process for submitting a form from a different webpage?

I am working on a website with two pages. Each page has a header with navigation tabs to move between page 1 and page 2. When a tab is clicked, I want the selected page to re-POST to the server for a quick refresh before displaying. There is a form on e ...

Struggling with making /api/login/ function properly - using JavaScript and Reddit

Oh no, I've reached my limit of attempts... just received the message "you are doing that too much. try again in 27 minutes." So, I decided to come here and seek help. Here is the request I am making URL: http://www.reddit.com/api/login/ Headers: ...

${IDHERE} element's text color not changing when tab is switched

One dilemma I encountered involves displaying a percentage on a webpage with 2 tabs. The percentage is originally shown on the tab that is open when the page loads. The JavaScript code I used is quite straightforward: adaPercentColor(percent, ada) { ...

Displaying the unique values based on the key attribute

I'm developing a category filter and struggling to showcase the duplicate options. Within my array of objects: filterData = [ { name: 'Aang', bender: 'yes', nation: 'Air', person: 'yes', show: 'ATLA&apo ...

connect lesson to operation

How can I dynamically bind a class in vue JS based on a function? Here is my code snippet: :class="{{this.isMobile() ? 'mobile-chip-overflow' : 'chip-overflow'}}" However, I'm encountering a console error saying "isMobile is nul ...

Issue with chunk content script within a Nuxt 3 application

Operating System: Windows_NT Node Version: v18.18.2 Nuxt Version: 3.9.1 CLI Version: 3.10.0 Nitro Version: 2.8.1 Package Manager: [email protected] Builder: - User Config: ssr, css, app, modules, i18n, sitemap, image, de ...

Angular service that iterates through each $q.promise

Here's the function I am working with: this.getBenchmarkData = function () { var benchmarkData = []; var d = $q.defer(); users.forEach(function(user){ var dataArray = []; modules.forEach(function (module) { ...

One requirement for a directive template is that it must contain only a single root element, especially when using the restrict option to E

I am currently managing an older AngularJS application (v1.3.8). Why is the demo application showing me this error? The directive 'handleTable' template must have only one root element. sandbox.html <!DOCTYPE html> <html> <he ...

The AJAX form processing led to an unhandled TypeError

I have been working on a contact form for my website and want to implement AJAX/PHP to send the data. When I click the submit button, I encountered this error message: Uncaught TypeError: Cannot read property 'mode' of undefined at Function ...

Enhance communication system by optimizing MySQL, JavaScript, and PHP chat functionality

I have created a chat application using Javascript, PHP, and MySQL for two users. Every 3 seconds, it makes an AJAX request to a PHP file to retrieve messages from the database and update the page. Currently, the PHP query used is: SELECT * FROM tmessages ...

extracting specific column information from an xlsx file using Vue.js

Is there a way to read an Excel file column by column and convert the data into JSON format? I am facing difficulties in fetching data from a specific column in an xlsx file using Vue.js. Can anyone assist me with getting data from a particular column in ...