What is the best way to showcase the array data of two description values in a Vue v-for loop?

    An array called ledgerDetails contains 32 data elements. These details are displayed in a vue v-for loop. However, within the loop, I need to show specific details from invoiceDescriptions (23 data elements) and paymentDescriptions (12 data elements) based on certain conditions. How can this be achieved?
    
    Code Example:
    
    <tr v-for="(ledger, index) in ledgerDetails" :key="index">
                  <td>
                    {{ formatDate(ledgerDetails[index][0]["create_datetime"]) }}
                  </td>
                  <td>
                    <span
                      v-if="
                        isNaN(
                          ledgerDetails[index][0]['public_number'] &&
                            userDetails['User']['account_id'] ==
                              ledgerDetails[index][0]['public_number']
                        )
                      "
                    >
                      {{ paymentDescriptions[index] }}
                    </span>
                    <span
                      v-if="(
                        ledgerDetails[index][0]['public_number'] == 0 &&
                        ledgerDetails[index][0]['type'] == 'creditNote')
                      "
                    >
                      Refund
                    </span>
                    <span v-else>
                      <span v-if="invoiceDescriptions !== 'undefined'">
                        {{ getInvoiceDesc() }}
                      </span>
                      <span v-else> </span>
                    </span>
                  </td>
                  <td></td>
                  [...]
                </tr>


How can the details of invoiceDescriptions and paymentDescriptions be displayed within the ledgerDetails for loop?

Data: 

paymentDescriptions: [{PaymentInfoCheque: {description: "Cash"}}, {PaymentInfoCheque: {description: "Cash"}},…]
0: {PaymentInfoCheque: {description: "Cash"}}
1: {PaymentInfoCheque: {description: "Cash"}}
2: {PaymentInfoCheque: {description: "Cash"}}
[...]

ledgerDetails: [[,…], [,…], [{type: "invoice", create_datetime: "2020-10-14 14:46:28", total: "100.82417582418",…}],…]
0: [,…]
0: {type: "invoice", create_datetime: "2020-09-03 17:15:13", total: "100", public_number: "4", id: "4",…}
[...]

invoiceDescriptions: [[{description: "test"}], [{description: "test Period from 25 Sep 2020 to 29 Sep 2020,test"}],…]
0: {description: "test"}
[...]

Answer №1

I hope I grasped the essence of your question correctly as it seems to require further clarification. You should establish a connection between payment data and ledgerDetails objects by adding a unique key, such as paymentID, to the payment object. Additionally, include an extra attribute in the ledgerDetails object that references the payment's ID.

Example of ledgerDetails object:

{
  paymentId:500,
  otherAttribute...
}

Each payment object should have a distinct ID like so:

Example of payment object:

{
  paymentId:500
}

Furthermore, you need a method to retrieve payment information based on the object data or ID from the store. This can be achieved through the findPaymentById method:

findPaymentById(paymentId) {
 return paymentList.find(i => i === paymentId)
}

Once these steps are in place, you can access the payment details from ledgerDetails using the paymentId retrieved from the object. Display the details using another method.

When utilizing v-for, you can omit the index since it returns the complete object list for direct access without indexing:

<div v-for="ledgerItem from ledgerDetails">
payment details :
{{ findPaymentById(ledgerItem[0].paymentId) }}
</div>

Note that in this example, I used zero-based indexing (ledgerItem[0]) because ledgerItem is an array of objects within ledgerDetails.

If my interpretation is incorrect, please let me know so I can offer additional assistance.

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

"Can you provide guidance on displaying a form for a specific element based on its unique ID

I am trying to display the edit form when clicking on a specific image, but it is currently showing for all tasks. I need help in figuring out how to make it show only for one task. I attempted to use useState to change the boolean value "active" to show ...

Uploading my application on multiple servers after making changes using AngularJS and PHP

Currently, I am working on an angular-php web application that is live online for multiple users, each on their own subdomain. These subdomains include: sub1.mydomain.com sub2.mydomain.com sub3.mydomain.com sub4.mydomain.com sub5.mydomain.com Issue: An ...

Is it advisable for postcss plugins to list postcss as a peer dependency?

I'm trying to incorporate the PostCSS Sass Color Function into my project. Unfortunately, I encountered this error: PostCSS plugin error: Your current version of PostCSS is 6.0.22, while postcss-sass-color-functions requires 5.2.18. This discrepa ...

The Socket.io server is experiencing issues with the "connection" event not firing, and the client event is also not being triggered

I've been struggling to set up an express backend with socket io. No matter what I try, the connection events just won't fire. Both the server and client are using version 3.1.2, so that's not the issue. When I start the client app, I see so ...

React Hooks encountering issues with keydown/up events functionality

Currently, I am in the process of implementing arrow-based keyboard controls for a game that I have been developing. In order to stay updated with React, I decided to utilize function components and hooks. To showcase my progress, I have put together a dem ...

Styling a Pie or Doughnut Chart with CSS

I am working on creating a doughnut chart with rounded segments using Recharts, and I want it to end up looking similar to this: Although I have come close to achieving the desired result, I am encountering some issues: Firstly, the first segment is over ...

svg-to-json.js | The mysterious disappearing act of my file

After completing the installation process for svg-to-json.js as detailed in my previous post, I ran the command: node svg-to-json.js filename.txt The expectation was that a .json file would be generated, but I couldn't locate it. Is it supposed to ...

I am experiencing issues with launching chromium while running Puppeteer on Windows 11 using node js v19.4

Upon following the installation instructions in the documentation to install puppeteer with npm install puppeteer, I attempted to run the example for downloading a webpage as a PDF. However, every time I try to execute the code, Node.js returns the followi ...

Can anyone assist me with this HTML/jQuery code?

Despite my efforts, I've been unable to achieve success. The challenge I'm facing is with duplicating controls for adding images. I have a button and a div where the user can choose an image by clicking the button. The selected image appears in ...

Tips for managing erroneous data in csv files using Node.js

I am currently working on an application that parses csv files using the csv module. It is functioning well, but I am facing a problem where if there is a bad row in the csv file, the entire process fails. Is there a way to skip bad rows and continue stre ...

I possess a high-quality image that I wish to resize while maintaining its resolution and clarity

I'm struggling with optimizing images for retina display on my website. I typically use the drawImage method, but I have a collection of large images (canvas drawn) that I want to use at half their size while maintaining image quality. Does anyone kn ...

The requestify Node module encounters issues when the body contains special characters

My current project involves the use of node.js and a library called requestify. Here is the snippet of code causing some trouble: console.log('body'); console.log(body); return new Promise(function (f, r) { requestify.request(myurl, { ...

What is the best way to repair a react filter?

Recently, I successfully created a database in Firebase and managed to fetch it in React. However, my current challenge is to integrate a search bar for filtering elements. The issue arises when I search for an element - everything functions as expected. ...

What is causing the Invalid left-hand side error in the postfix expression at this specific line of code?

I encountered an error stating "invalid left-hand side in postfix expression" while trying to execute this particular line of code data: 'Action=AutionMaxBid&AuctionItemID='+<?php echo $bidItemID ;?>+'', This error occurred d ...

Numerous CSS/JS Dropdown Menus

I am seeking the ability to implement a dropdown through CSS in various locations within my HTML prototype. This implies that I require the capability to position multiple dropdowns anywhere on the page. Currently, I utilize this method to generate a sing ...

Transmit the canvas image and anticipate the AJAX POST response

I need to send canvas content to my API endpoint using ajax and wait for the response before moving on to the next function. Here is my current sending function: function sendPicture(){ var video = document.getElementById('video'); var canvas ...

How to make a GET request to a Node server using Angular

I am currently running a node server on port 8000 app.get('/historical/:days' ,(req,res,next){..}) My question is how to send a request from an Angular app (running on port 4200) in the browser to this node server. Below is my attempt: makeReq ...

Issue with the statement not being recognized for counting the space bar

I created a counter but I'm having trouble incorporating if statements For example: if (hits == 1) {alert("hello world1")} if (hits == 2) {alert("hello world2")} if (hits == 3) {alert("hello world3")} if (hits == 4) {alert("hello world4")} This is t ...

What is the best way to transfer all li elements with a certain CSS style to a different ul?

I have a task to relocate all the <li style="display:none;"> elements that are currently nested under the <ul id="bob"> into another <ul id="cat">. During this relocation process, it is important that all the classes, ids, and CSS style ...

Executing a function with arguments within a separate function

I've been working on creating a scheduler function that can randomly call another function with parameters. Here's the JavaScript code I have so far: function scheduleFunction(t, deltaT, functionName) { var timeout; var timeoutID; ...