Exploring Vue.js with a v-for loop to extract data from a nested JSON array

Initially, I receive data from a websocket connection and parse it to store in my state.

this.connection.onmessage = (message) => {
    let messageData = JSON.parse(message.data);
        commit("UPDATE_MESSAGES", messageData);  
    };

Next, in my component, I access the data through a computed property:

computed: {
   messages() {
      return this.$store.getters.getMessages
      },   
    },

The data structure is as follows:

{
    "op": "utx",
    "x": {
        "lock_time": 0,
        "ver": 1,
        "size": 405,
        "inputs": [
        {
            "sequence": 4294967295,
            "prev_out": {
                "spent": false,
                "tx_index": 0,
                "type": 0,
                "addr": "3Noh57x1AJqoUnZcBdavASbZS8JgH2YSV9",
                "value": 12677037,
                "n": 1,
                "script": "a914e79dd0f494dfe5a26c992d68ca1e29ac9ef6a34b87"
            },
            "script": "2200206b037d5a1989c15bbab85168c2b1bcff8467ec391721340c2870bdd94d33239d"
        },
        ...
    }
}

This is how the data is received from the server, and it cannot be modified on the server side.

I want to display certain values from the data in my template, but I am having trouble accessing deeper nested levels.

<div class="transaction__block" v-for="message in messages" :key="message.id">
    <div v-for="x in message.x" :key="x.id">
        {{ x }}
        <div v-for="input in x.inputs" :key="input.id">
          {{ input }}
        </div>
    </div>
</div>

I can display {{ x }}, but I'm unable to go deeper into {{ input }}.

In my scenario, I need to display x.inputs.addr for every input and then x.out.addr and x.out.value for every out.

Any assistance would be appreciated.

Answer №1

Let me give it a shot =)

// your code... 
  <div v-for="(input, index) in message.x.inputs" :key="index">//Is it possible to use the index instead of an id attribute for input since it is not available?
    <p>{{ input.prev_out.addr }}</p>
    <p>{{ message.out[index].addr }}</p>
    <p>{{ message.out[index].value }}</p>
  </div>
</div> 
//...

I believe by doing this, you can access ìnput.prev_out.addr and if they match with out[index].addr, the values should be the same =)

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

A guide on integrating MongoDB, Mongoose, Express JS, and Node JS for effectively adding prices

Currently adding various documents to the database: await TestMOdel.insertMany([ { Model: "Samsung", price: 45000, OS: "MS DOS", }, { Model: "Wipro", pr ...

Employing Vue to perform validation on form fields utilizing a method

I am relatively new to Vue, so I appreciate your patience with me. Currently, I am working on a codebase that was created by another developer. The application is simple and consists of a form for data collection. One of the fields in the form is a postcod ...

Executing a series of tests using Postman

Is running multiple requests in a postman script feasible? I have an endpoint: http://localhost/gadgets/{id}/buy This endpoint sets a flag in a gadget object/entry based on its id. With hundreds of gadgets, can I use a shared file of ids to create and run ...

When the application is converted into static files, the dynamic routes fail to function properly

I have a website that is statically exported but has dynamic routes. During development, the site works fine. However, when I build and export it, then serve the static files using serve, an issue arises. If you go to the site root and click on a link th ...

Display a div using data from a Model in MVC

I am working with a model List that has fields ContainerId (div id) and Code (HTML code), which I am passing to a Razor View. Can you suggest the most effective way to display the code from the model in the containerId? My initial thought is to utilize j ...

When utilizing jade.compile for compiling a jade template containing mixins or included partials

I'm currently exploring solutions for this challenge. The issue at hand involves compiling a jade template for an email campaign, but the file I am attempting to compile is a mixin that includes some partials. Here's an example: controllers/us ...

Should CSS variables be defined within the render method of a React component?

Yesterday, I mistakenly created and deleted a post. Now, I am facing an issue with creating a component that requires specific styling. The problem arises when the componentDidMount() method causes flickering during the rendering process, as it takes some ...

AngularJS and CodeIgniter collaborating to bring server-side pagination

I am currently working on integrating pagination using AngularJS and CodeIgniter. The current implementation requires fetching all records at once. However, I aim to modify it so that the data can be retrieved one page at a time from the server during run ...

Error parsing PHP string arrays into JavaScript string arrays

My attempts to convert a name string array from PHP to Javascript have been unsuccessful. var name = <?php echo json_encode($eventname); ?>; and var name = new Array("<?php echo implode('","', $eventName);?>"); I expected the ou ...

Can the file size and extension be checked simultaneously before uploading?

I have successfully implemented file extension validation using jQuery, however, I am encountering issues when trying to validate the file size. I am currently using the latest version of jQuery. THE CODE FOR FILE EXTENSION AND SIZE VALIDATION ISSUES: ( ...

Angular JS implementation of the undo redo feature allows users to reverse or

My challenge involves a large object stored in $rootScope with over 100 objects, each containing hierarchies of objects and arrays. I am seeking to watch the entire $rootScope using deepWatching (setting the 3rd parameter of $watch to TRUE). The issue ari ...

Tasks involving computed getters

Is it acceptable to assign properties in computed getters? props: invoice: type: Object computed: total: @invoice.subtotal = { some expression } I am considering this because the invoice object is shared among several other components, and ...

What is the benefit of using $q.all() with a single promise in AngularJS?

As I delve into this codebase, one snippet keeps popping up: $q.all([promise]).then(responseFunc); However, I find this confusing. After reading the documentation, I wonder why not simply use the following, as it's just a single promise... promise. ...

Tips for manipulating the appearance of a parent element using CSS and VueJS

I'm currently working on a project where I need to loop through a set of users in order to create a table using the VueJS 'for' statement. One specific column is named "approved". If the value in this column is true, I want the entire row i ...

Importing Vue Components

Despite numerous attempts, I am still unable to figure out how to efficiently import all Vue single file components from a directory at once. Allow me to elaborate... For instance, I have a directory named Add/Items where I have stored various Vue compone ...

Scrolling on a div can be used to create a looping magnification or scaling

Is there a way to create a seamless loop between #box2 and #box using this fiddle? I want them to reveal themselves in a continuous loop with infinite scroll. Each time one box fills the frame, the next one should appear in the distance, repeating indefini ...

Error in Angular 2: The requested URL https://imgur-apiv3.p.mashape.com/ cannot be loaded. The use of a wildcard '*' is not allowed in the 'Access-Control-Allow-Origin' header

I'm attempting to upload an image using the imgur API at: . However, I keep encountering this error: XMLHttpRequest cannot load . A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credential ...

The image is failing to animate according to the PNG sequence function

Enhanced Functionality: Upon clicking the "Tap Here" image button, a function called "GameStart()" is triggered. This function ensures that the main image "Star" descends down the page from the top through an animated sequence using png logic. The propose ...

Add numerous submit buttons within a form. Upon clicking on a button, the form should be submitted to a specific URL using AJAX

I have a form with two submit buttons: one labeled as "SUBMIT" and the other as "SCHEDULE NEXT ROUND". When a user clicks on the "SUBMIT" button, the form values should be stored in the database and redirect to the view page. If they click on the "SCHEDULE ...

As the user types, the DD/MM/YYYY format will automatically be recognized in the

In my React component, I have an input box meant for entering a date of birth. The requirement is to automatically insert a / after each relevant section, like 30/03/2017 I am looking for something similar to this concept, but for date of birth instead of ...