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

Step-by-step guide on integrating Bulma page loader extension as a Vue component

Is there a way to integrate the Bulma-extension page-loader element as a Vue component in my project? I attempted to import page-loader.min.js and use it, but unfortunately, it didn't work as expected. <template> <div class="steps"> ...

drawImage - Maintain scale while resizing

I am currently working on resizing an image using drawImage while maintaining the scale. Here is what I have so far... window.onload = function() { var c = document.getElementById("myCanvas"); var ctx = c.getContext(" ...

The Vue.js route is not aligning with its defined path, causing a mismatch

Attempting to develop a Vue SPA app, but encountering an issue with the routes not matching what was defined in the router. Despite all configurations seemingly correct, there is confusion as to why this discrepancy exists. What element might be overlooked ...

I am looking to retrieve products based on category alone, category and model together, or simply obtain all products in one go. At the moment, I am utilizing three distinct endpoints

I have 3 endpoints on my backend that fetch products based on certain criteria. I'm considering whether to refactor the logic and combine them into a single endpoint/function. Currently, my routes are structured as follows: router.get('/products& ...

Please ensure that the menu is included within the HTML file

How can I include a menu from menu.html into index.html? The content of menu.html is: <li><a href="home.html">Home</a></li> <li><a href="news.html">News</a></li> In index.html, the code is: <!docty ...

AngularJS Partial Views: Enhancing Your Website's User Experience

As a newcomer to the world of Angular, I am seeking guidance on a specific issue. I have encountered a one-to-many relationship scenario where one Category can have multiple Product items. The challenge lies in my layout page setup where I display various ...

Component fails to re-render after token refresh on subsequent requests

Here is my axios-hoook.js file, utilizing the axios-hooks package. import useAxios from 'axios-hooks'; import axios from 'axios'; import LocalStorageService from './services/local-storage.service'; import refreshToken from &ap ...

Assign the filename to the corresponding label upon file upload

I've customized my file uploader input field by hiding it and using a styled label as the clickable element for uploading files. You can check out the implementation on this jsFiddle. To update the label text with the actual filename once a file is s ...

Inspecting Facebook links

Currently working on a website and interested in incorporating a feature similar to what Facebook has. I'm referring to the link inspector, but I'm not entirely sure if that's its official name. Allow me to provide an example to clarify my r ...

Divide a single image into several smaller images and enable clickable links on each separate image, similar to an interactive image map

Challenge: I am faced with the task of splitting a large image (1920px x 1080px) into smaller 40px by 40px images to be displayed on a webpage. These smaller images should come together seamlessly to recreate the original full-size image, with 48 images a ...

Creating a series of promises in a structured chain

How can the code structure be improved, especially regarding exception handling within a "promise chain"? $("#save").click(function(e) { e.preventDefault(); let $self = $(this); let profile = {} $self.prop("disabled" ...

Vue.js failing to update when object property changes

<v-container class="text-center hyp-container pa-4"> <v-row> <button @click="toggleForm">Create new target</button> </v-row> <v-row> <v-dialog v-model="showConfirmDelet ...

Schema Object for Validating Vue Prop Types

React allows you to specify that a prop is an object and define the types of its properties, known as the shape. However, in Vue, it appears that the only method available to determine if an object matches a specific shape is by using the validator funct ...

While conducting tests on a Vue single file component, Jest came across an unforeseen token

I need help with setting up unit tests for my Vue application that uses single file components. I've been trying to use Jest as mentioned in this guide, but encountered an error "Jest encountered an unexpected token" along with the details below: /so ...

Move the material ui menu to the far left side of the page

How can I adjust the menu to align with the left side of the page without any gaps? I've tried various methods but it's not moving to the left. Any suggestions? Here is the relevant code snippet: <Menu an ...

Tips for storing a JavaScript variable or logging it to a file

Currently working with node, I have a script that requests data from an API and formats it into JSON required for dynamo. Each day generates around 23000 records which I am trying to save on my hard drive. Could someone advise me on how to save the conte ...

Is a non-traditional fading effect possible with scrolling?

I have implemented a code snippet to adjust the opacity of an element based on scrolling: $(window).scroll(function () { this = myfadingdiv var height = $(this).height(); var offset = $(this).offset().top; var opacity = (height - homeTop + ...

Troubleshooting Tips: Investigating a Service Call in AngularJS 2 using ES6 Syntax

MY DILEMMA: I have recently started learning Angular2 and found myself wanting to debug a service call. The service appears to have been properly called, as evidenced by the view display. However, when trying to log the content of the variable holding t ...

Numerous textareas fail to function properly according to JQuery's standards

Need help with resizing multiple textarea elements dynamically as the user types in them (on the Y-axis). Currently, I have code that successfully resizes a single textarea, but it does not work when there are multiple textareas on the page. Here is the c ...

Incorporate SVG as a module in the updated Vite.js 2.9 environment and Vue.js 2.7 integration

I am currently in the process of transitioning my project dependencies from Vue CLI to Vite. Due to constraints, I need to continue using Vue.js 2.7 and cannot upgrade to Vue.js 3 at this time. Previously, I utilized vue-svg-loader with Vue CLI but now I ...