An issue arises when trying to showcase necessary data within vue.js templates

I'm having an issue with displaying a specific value based on an onclick event. The value is taken from an object in the bookData array:

this.bookData.push(
            {
            avalable: true, 
            titles: [title, id],
            author: authors,
            descriptions: [description, id]
            })

I've written some code to display the descriptions value using an onclick event within vue.js templates. All values are related to this object (with keys fetched from a Google Books API). Here's the code snippet:

//bookData == books  when transferred to the child component...



 <section  v-for="(bookTitle, index) in books"
      v-bind:key="index"
      
      >
    <button
      :ref="'el'+ index"
      @click="hidden = !hidden"
      class="list-group-item"
      v-if="bookTitle.titles"
    >{{bookTitle.titles[0]}}
    </button>
    <p v-if="!hidden">   
      {{
        bookTitle.titles[id] == bookTitle.descriptions[id] ?
        "'DESCRIPTION:'\n" + bookTitle.descriptions :
        console.log("it works")
        }}
      </p>

...

data() {
      return {
       hidden: true,
      }
    }

When I click on any button, all description values are displayed below all the button elements instead of only showing the description corresponding to the clicked button. I want the desired description to be shown below the clicked button and only once.

If anyone has a solution (maybe a method inside the methods:{}), any help or advice would be greatly appreciated. I am new to Vue.js. Thank you in advance. :)

Answer №1

The reason for the issue is that a single parameter hidden is being used to control all elements. To resolve this, it is recommended to update the object structure as shown below and utilize item.hidden to manage individual items:

            {
            avalable: true, 
            hidden: true,
            titles: [title, id],
            author: authors,
            descriptions: [description, id]
            }

For more information on this topic, please see the following link:
TreeView in Vue not rendering subfolder content correctly

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

eliminating list item from unordered list depending on the input of either first or last name

My objective is to refine a lengthy list as the user types in a search for a specific person by first or last name. The current code I have functions adequately, but encounters an issue when there is a space in the input field. My goal is to allow users to ...

Can jQuery effortlessly glide downward, come to a stop, continue downward, and then move upwards?

My webpage features a large table created and populated automatically every minute using ajax. The code structure is as follows: $(document).ready(function(){ setInterval(function(){ $.ajax({ //code to call backend, get the data, ...

Transform an array into an object, organizing values according to their even or odd index positions

I need help converting an array into an object where the keys are based on whether the index of the array is odd or even. For example: Input: ["name", "Tom", "age", 20] Output: {"name": "Tom", "age": 20} I know this can be achieved using basic JavaSc ...

Can MUI Snackbar be aligned relative to its parent div instead of the entire page?

My approach involves using a combination of Material UI's Snackbar and Alert components to show Success or Error messages after conducting a database Post action. The standard usage of Material UI offers the capability to position these messages on th ...

I noticed that when I include the www in the URL, I am unable to retrieve the API results. However, when I exclude the

Whenever I try to access my website through www.mywebsite.in, it fails to display my data. However, if I visit the site without the www prefix, everything works fine and I can retrieve data from the database. I'm currently utilizing APIs for both get ...

Using Three.js to ensure that child object3d expands within the boundaries of its parent object

In this scenario, I have 2 Object3Ds with one nested inside the other: var obj1 = new THREE.Object3D(); var obj2 = new THREE.Object3D(); obj1.add(obj2); Assuming obj1 is AxB units wide, how can I instruct obj2 to match that size? Essentially, how can I m ...

Sending Image Data in Base64 Format with Ajax - Dealing with Truncated Data

My current challenge involves sending Base64 image data through ajax to the Server. I've noticed that sometimes all the pictures are successfully sent, but other times only a few make it through. Does anyone have suggestions on how to implement error ...

Angular $watch not working as expected

I have a specific directive code: .directive('myDirective', function(){ 'use strict'; return { restrict: 'A' , link: function(scope, element, attrs) { var count = 0; function d ...

Progressive zoom effect applied to an image in a JavaScript slideshow

Can someone assist me in replicating the zooming effect demonstrated in this code snippet: `http://codepen.io/docode/pen/EjyVQY`. I am specifically focusing on the zooming feature of this slideshow. How can I replicate this zooming effect in JS rather t ...

Tips for creating a mandatory textarea input field

It's pretty straightforward - I have a textarea that is set to required, but it only alerts the user if you actually click inside the text area. If you try to submit without clicking inside, it won't prompt the alert. Take a look at this Fiddle ...

Postpone the appearance of a pop-up message, make it show up only once

Is it feasible to create a pop up that appears after 4 seconds and stays visible until the user interacts with the mouse? The pop up should not appear if the user scrolls before it shows. You can refer to the image for more details on the pop up box :) &l ...

The autocomplete feature in React is not displaying properly due to a problem with rendering

I am currently working on creating an autocomplete/autosuggest search bar using the Material-UI library with data fetched from an API. Below is a step-by-step breakdown of the code implementation. We first define the options for the autosuggest search bar ...

Retrieving an item from AsyncStorage produces a Promise

Insight I am attempting to utilize AsyncStorage to store a Token after a successful login. The token is obtained from the backend as a response once the user clicks on the Login button. Upon navigating to the ProfileScreen, I encounter difficulties in ret ...

Tips for creating curved Extjs area and line charts with a gentle radius to soften the sharp curves

I have been working on a mixed charts component for Extjs, and I noticed that the curves appear too sharp. I am unable to find a configuration option to add radius to the curves. If anyone has experience with this issue, could you please share a method t ...

The console log is not being displayed in my Redux reducer and it is returning an undefined

I'm facing an issue with my Redux application after integrating JWT into my Nest API. Below is the code snippet from my reducer: export default function reducer(state = {}, action) { switch (action.type) { case 'USER_LOGIN_SUCCESS&apo ...

Having trouble getting the popover window to appear in Bootstrap when utilizing the modal class?

I attempted to create a responsive image gallery using the bootstrap framework. Each image has its own modal class, but when I click on an image, no popup window appears, only a dark screen is displayed. I have checked this in the Bootstrap documentation ...

Encountering module resolution issue following npm-link for the shared component repository

Attempting npm-link for the first time to establish a shared component repository, and encountering an issue. The project seems to be linked correctly based on this message: /Users/tom.allen/Development/main/project/node_modules/@linked/project -> /usr ...

There appears to be an issue with the addrow() function in JavaScript

function addNewRow() { var medication = document.getElementById("medicinename"); var timeOfDay = document.getElementById("time"); var treatmentDuration = document.getElementById("duration"); var timing = document.getElementById("when"); ...

Changing multiple tags in JavaScript within an HTML document

Here is the JSON data I have: [ { "menu": { "MenuID":"1", "OmfID":"1", "menu_name":"Coyote Blues Louisiana Menu", "menu_description":"Full menu served all day.", "menu_note":null, "currency_symbol":"$ ...

Pattern to identify a 32-character string comprising a mix of letters and numbers

I am in search of a JavaScript regex pattern that can identify strings with the following format... loYm9vYzE6Z-aaj5lL_Og539wFer0KfD pxeGxvYzE6o97T7OD2mu_qowJdqR7NRc gwaXhuYzE6l3r1wh5ZdSkJvtK6uSw11d These strings are always 32 characters long and conta ...