Exploring nested data structures in Vue.js

Within my Vue-app, I am attempting to iterate through an array of data that contains multiple checkboxes.

filters: [
   {
    name: "Sales & marketing",
    open: false,
    items: [
        {
            employees_cvr: {
                placeholder: "employees",
                checked: false,
                click: data => {
                    ...
                }
            },
            employees_pnr: {
                placeholder: "employees_pnr",
                checked: false,
                click: data => {
                    ...
                }
            },
            date_of_origin: {
                placeholder: "Date of origin",
                checked: false,
                click: data => {
                    console.log(data);
                }
            },
            company_search: {
                placeholder: "Search for companies",
                checked: false,
                click: data => {
                    ...
                }
            }
        }
    ]
}

However, when I attempt to loop through the data like this:

<div v-for="filter in filters" :key="filter.id" class="category">
    <label @click="filter.open = !filter.open">{{filter.name}}</label>
    <div class="category__rows">
       <ul v-show="filter.open">
         <li v-for="item in filter.items" :key="item.id">
           <Checkbox v-bind:data.sync="item" />
         </li>
       </ul>
   </div>
</div>

The issue arises as I am able to display the name from the object, but not the items within. Upon clicking the label to set the state as open = true, the <ul> is visible but devoid of any data.

Can someone please assist me in identifying my mistake and provide guidance?

Answer №1

If you are currently iterating through the array filters.items, which contains a single object with multiple properties, consider iterating through that one object instead.

To do this, update your code like so:

       <li v-for="item in filters.items[0]" :key="item.id">
           <Checkbox v-bind:data.sync="item" />
         </li>

By making this change, you will be looping through the properties of the object rather than the array itself.

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

JavaScript confirm function fails to validate a required field validator

Utilizing the required field validator to validate a text box and prompting for confirmation on the click of a submit button using the confirm() function in JavaScript has posed a challenge. Upon pressing OK in the confirmation box, the page refreshes an ...

Variable assigned by Ajax no longer accessible post-assignment

Recently, I've written a script to fetch data from a SQL database and now I'm in the process of creating a JS wrapper for it. Utilizing certain functions, I call the script and extract information from the DB as soon as it becomes available. var ...

How can I make my webpage unselectable except for specific content within a div using CSS and JavaScript?

During a live editing session, I am looking to make only specific portions of the page selectable. Can someone provide guidance on how to disable selection for everything except within a particular div? ...

Something is not quite right when the page is loading in a Ruby on Rails application

In the process of developing a wiki clone, I am faced with an issue involving JavaScript. When I navigate to a specific page by clicking on a link, the JavaScript does not function properly until I refresh the page. The JavaScript aspect mainly involves an ...

Is there a way to effortlessly refresh a viewpage with fresh data directly from Firebase?

I am trying to update my HTML page with new data from Firebase in real time without having to refresh the entire page. However, I am facing issues where the view is not updating automatically. How can I achieve this? In my JavaScript file, I query Firebas ...

Angular login/signup modal/dialog component for seamless user authentication

Currently, I am working on adding a login/signin dialog to my app similar to the one used by Medium. After doing extensive research online, I have decided to use the $modal from angular ui-bootstrap for this. Can anyone please recommend a tutorial that wil ...

Is it possible to transfer a variable to a modal window by clicking on a link?

Here is a link with sample data value "data-id" that I want to pass: <a href="#edit_task" data-toggle="modal" data-id="WAH"><i class="fas fa-edit fa-lg fa-fw"></i></a> Javascript code to open the modal and assign the data value to ...

The router component in "react-router-dom" is not functioning properly

My goal is to explicitly utilize history in my project. While I am familiar with BrowserRouter, I prefer to use Route and make history one of its properties. Upon running the program, I encounter this page: enter image description here Below is my AppRout ...

directive for form validations is malfunctioning

I am a beginner with AngularJS and I'm currently working on writing a directive that wraps an input box inside a form tag, followed by a 'div' element which includes validation. Unfortunately, the validation is not functioning as expected. Y ...

Tips for implementing the quill-image-drop-module with Vue 3

I am currently utilizing the vueup/vue-quill package for Vue 3 and I would like to incorporate the kensnyder/quill-image-drop-module. This is the snippet of my code: Main.js import { QuillEditor } from '@vueup/vue-quill'; import '@vueup/vu ...

Prevent the Swiper slider from autoplaying while a video is being played, and automatically move to the next slide once the video is paused or

<div class="swiper mySwiper"> <div class="swiper-wrapper"> <div class="swiper-slide"> <video-js id="6304418462001" class="overlayVideo" data-account= ...

How to Force Redirect to HTTPS on Elastic Beanstalk with Node.js and Express

Seeking assistance in setting up a site to enforce HTTPS (redirecting from HTTP). Our HTTPS is configured through AWS Elastic Beanstalk, but currently both HTTP and HTTPS are accessible. After reviewing various resources, such as this one, I attempted the ...

You cannot edit FabricJS IText (and Textbox) within the context of React Bootstrap

I'm having trouble incorporating a canvas into my React Bootstrap component. Specifically, I am encountering issues with the text editing functionality when using IText and Textbox. Despite setting the corresponding properties, I am unable to modify t ...

Having trouble retrieving hidden values from a new Angular/JavaScript window

I have created a form inside a component HTML <button type="button" (click)="myForm(i)"> TypeScript myForm(i) { let form = document.createElement('form'); form.setAttribute('action', this.urlAddr); form.setAttribute ...

Error: You forgot to close the parenthesis after the argument list / there are duplicate items

I have already tried to review a similar question asked before by checking out this post, but unfortunately, I still couldn't find a solution for my problem. Even after attempting to add a backslash (\) before the quotation mark ("), specificall ...

Issue with md-stretch-tabs in Angular-Material causing a problem

I am in the process of developing an Angular-based application. ISSUE: I included md-stretch-tabs in my md-tabs element, but when I switch to tab#2, the tab retracts as if there is not enough space to flex. Is this problem related to dependencies or the c ...

A function cannot be used with Random Song Loop

Recently delving into the world of JavaScript, I encountered a peculiar issue. When attempting to execute the following code within a function, nothing displays in the console. Yet, after testing it without the function, the expected strings appear as inte ...

Executing $(this).parent().remove() triggers a full page reload

A unique feature of my webpage is that with just a simple click of a button, users have the ability to dynamically add an endless number of forms. Each form contains fields for user input and also includes a convenient delete button. var form = " Name ...

Combining NodeJS with PHP: A Seamless Integration

They say NodeJS is perfect for creating real-time chat applications and I'm eager to add a chat feature to my website. Right now, I have the design ready and need to work on the back-end code. However, when I use socket.io + express, things don' ...

The Angular-Express combination is not being satisfied by the get request

`, I am a newcomer to the MEAN stack environment and I am struggling with fetching data from my Express server (which is set up with MongoDB) when a button is clicked. Even though the function associated with the button click is executed, the request does ...