Exploring the Depths of Nested Arrays in VueJS: A Guide to Efficiently

I have an array containing several multi-dimensional arrays.

This is my API response:

0:  name : "name",
    address : "address"

        0:
            receipts :
                balance : 10,
                bill : 101, 
        1:  
            receipts :
                balance : 12,
                bill : 101, 

1:  name : "name",
    address : "address"

        0:
            receipts :
                balance : 13,
                bill : 101, 
        1:
            receipts :
                balance : 14,
                bill : 101, 

2:  name : "name",
    address : "address"

        0:
            receipts :
                balance : 15,
                bill : 101, 
        1:
            receipts :
                balance : 16,
                bill : 101, 

I am binding this data to an array.

this.reportResults=response.data;

In the code, I am looping through this array like this:

<ul>
            <li v-for="report in reportResults"> // this works fine
                <div class="row" style="background-color: #f4fbee;">
                    <div class="col-md-2">{{report.bill_no}}</div>
                </div>
           </li>
</ul>

However, I want to loop through the receipts as well. So, I wrote the following:

<ul>
                <li v-for="report in reportResults"> // this works fine
                    <div class="row" style="background-color: #f4fbee;">
                        <div class="col-md-2">{{report.bill_no}}</div>
                    </div>
                   <div class="row" v-for="receipts in report.receipts"> // this prints nothing
                       {{receipts.bill}}
                    </div>
               </li>
    </ul>

The inner loop prints nothing. However, if I print the raw data inside my second loop like {{receipts}}, it displays all the data. So, how can I loop through the receipts object?

Answer №1

As mentioned by @Chris G earlier, the solution has been provided in the comments section. Just to make it more visible, here is the answer:

<div class="row" v-for="receipt in report.receipts">{{receipt.bill}}</div>

Please note that I have corrected the spelling of "receipt" and removed the plural form when referencing a single item.

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

Implementing Role-Based Access Control (RBAC) with an express backend and passport authentication

I am currently in search of an RBAC package or a demonstration using middleware on Express router. My goal is to establish different roles such as admin, manager, and user during registration, and then verify these roles with each backend request. Althou ...

Utilizing jQuery.ajax() to retrieve the child div from a separate page

Can anyone help me figure out how to use jQuery ajax() to load two children contents from an external page? I want a pre-loader to display before the main content loads. Below is the code snippet that I have tried. $.ajax({ url: 'notification.htm ...

Tips for updating the firebase access_token with the help of the next-auth credentials provider

Can anyone help me with refreshing the Firebase access token when it expires? I need the token for API authentication, but I can't find any information online regarding next-auth and Firebase. Currently, I am able to retrieve the access token but str ...

The following MongoDB errors unexpectedly popped up: MongoNetworkError: connect ETIMEDOUT and MongoServerSelectionError: connect ETIMEDOUT

I've been working on a React and NextJS App for about a month now, utilizing MongoDB as my database through MongoDB Atlas. I'm currently using the free version of MongoDB Atlas. For the backend, I rely on NextJS's api folder. Everything wa ...

Integrate functionality to track elapsed hours in stopwatch timer

Struggling to incorporate hours into my JS Stopwatch timer, the math for calculating the hours section is proving difficult. This is what I have so far, but I suspect the issue lies within the h variable. function formatTime(time) { var h = m = s = ...

An easy way to enable mobility for BootstrapDialog on mobile devices

Currently, I am utilizing the library available at https://github.com/nakupanda/bootstrap3-dialog in order to create a dialog box. However, my issue arises when viewing the dialog on mobile devices where it exceeds the screen size. On desktops, adjusting t ...

Pull data from another domain's DIV using jQuery's load/ajax function

I need to load content from a different domain into a DIV on my JSP page. For example: $("#myDiv").load("https://www.google.com") The issue I'm facing is that the request is being blocked by the browser's same origin policy. I've explore ...

Explaining Vue.js actions and mutations in detail

Can someone help clarify the relationship between these functions for me? I'm currently learning about Vue.js and came across an action that commits a mutation. The Action: updateUser({commit}, user) { commit('setUser', {userId: user[&ap ...

When attempting to delete an item from Firebase using React, the re-render results in the item being

I'm currently in the process of developing an app to enhance my React skills, and I've chosen Firebase for data storage. Everything seems to be working fine as all items from Firebase are rendering properly. However, I've encountered an issu ...

Incorporating onPause and onResume functionalities into a YouTube video featured on a page built with Ionic 2

I'm encountering a minor problem with a simple demo Android app built in Ionic 2. Whenever a Youtube video is playing on the Homepage, if the power button is pressed or the phone goes into sleep/lock mode, the Youtube video continues to play. This is ...

Is there a way to retrieve the selected value from a dropdown menu using vue.js?

I have a parent Vue component structured like this: <template> <form> <div class="row"> <div class="col-md-4"> <form-select id="color" name="color" :data="color">Color</form-select&g ...

Troubleshooting: Jquery Toggle Issue When Used with Adjacent Div Element

I've been puzzling over this issue for hours now. The intention of this code is to display a div, but it's just not cooperating. <div id="butbr"> <div id="sup_nav"> <div id="stup" class="bxt1"></div> <div id= ...

You may encounter an error stating "Property X does not exist on type 'Vue'" when attempting to access somePropOrMethod on this.$parent or this.$root in your code

When using VueJS with TypeScript, trying to access a property or method using this.$parent.somePropOrMethod or this.$root.somePropOrMethod can lead to a type error stating that Property somePropOrMethod does not exist on type 'Vue' The defined i ...

Is there anything suitable to keep in SharedPreferences?

I'm working on a file explorer to sync an FTP directory on my phone. I want to know which files are new after each synchronization, even if the app is closed and reopened in the next session. My idea is to save an array of new files and compare it in ...

Exploring the application of Checklist-model in Angular

My goal is to have departments as titles and employees as subtitles. When the user checks a department title, all associated employees should also be checked. I am implementing this using fieldset and table in HTML with ng-repeat. It seems similar to this ...

Example of Next.js Authentication - redirecting according to authentication status, encapsulating within other functionalities

I'm currently working on a project using next.js with authentication. The authentication is set up and working, but I'm having trouble displaying the data in my navbar. Originally, I was using firebase for authentication, but now I have it set u ...

Best practices for incorporating packages in Vue.JS SPA applications

Currently, in my vue-cli/webpack project, I have been incorporating new packages using the command: yarn add <package> --dev These packages are stored in the package.json file under devDependencies. While the setup works smoothly, the build process ...

The ajax function is malfunctioning when called from an external JavaScript file

I am having an issue with a Registration page that only has UserName and Password fields. When I click on the Submit button, I want to be able to submit the new User Details using an ajax call with jQuery. I have tried defining an Insert function on butt ...

Tips for transferring a set-returning function to a LATERAL JOIN in PostgreSQL

Attempted Query: select created_at, sum((json_array_elements(shipping_lines::json) ->> 'price')::float) as shipping_price from t1 group by 1 Error Encountered: ERROR: aggregate function calls cannot contain set-returning function calls ...

Showing a Bootstrap.vue b-table containing nested arrays within arrays

I am facing an issue while trying to display data in a b-table. Normally, it works well with most data sets. However, when I encounter another array nested within the referenced array, the rendering is not done properly. While working on this problem, I ...