How to retrieve an unknown JSON key in Vue.js when using v-for loop?

I have developed a code analysis tool and I am looking to display my JSON data in a Vue table. The challenge is that I need the JSON key, which represents the package/file name of the directory whose data I want to showcase.

Below is an excerpt of the JSON structure (where "NULLY" is the package name):

"folderStatistics": {
          "NULLY": {
            "Statistiken": {
              "Werte": {
                "Felder": "0",
                "Konstruktoren": "0",
                "Methoden": "8",
                "Klassen": "1",
                "Codezeilen": "191"
              }
            },

And here is how my HTML looks:

<table class="table table-bordered">
      <thead>
        <tr>
         <th></th>
         <th>Felder</th>
         <th>Konstruktoren</th>
         <th>Methoden</th>
         <th>Klassen</th>
         <th>Codezeilen</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="value in folderStatistics.NULLY.Statistiken">
         <td>{{$key}}</td>
         <td>{{value.Felder}}</td>
         <td>{{value.Konstruktoren}}</td>
         <td>{{value.Methoden}}</td>
         <td>{{value.Klassen}}</td>
         <td>{{value.Codezeilen}}</td>
         </tr> 
      </tbody>

While this setup works with "NULLY", I want it to be dynamic. How can I achieve this? Is it even possible?

Answer №1

official documentation

If you have a variable called NULLY, you can use it in your view as shown below:

 <tbody>
    <tr v-for="(value, key) in folderStatistics[package].Statistiken">
     <td>{{key}}</td>
     <td>{{value.Felder}}</td>
     <td>{{value.Konstruktoren}}</td>
     <td>{{value.Methoden}}</td>
     <td>{{value.Klassen}}</td>
     <td>{{value.Codezeilen}}</td>
     </tr> 
  </tbody>

Check out this demo on jsFiddle.

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

Transforming a div into a clickable hyperlink

I have a JavaScript function that generates a div with a link inside it. Here is how the div and link are created: $('#info').find('#link').text("View"); //Creates a new link var eventLink1 = document.createElement('a& ...

Issue with array filter not functioning correctly upon page refresh when utilizing vue-router

I have a method (shown below) that functions perfectly when I'm directed from a <router-link>. selectedSpaceObj() { if (!this.selectedSpace) { return {}; } else { return th ...

Load HighCharts dynamically in a sequential manner

Currently, I am working on dynamically loading a variety of series based on user-selected projects. My tech stack includes Laravel 5.2, PHP 5.6, and HighCharts. I've successfully loaded one JSON file generated upon project selection. However, I aim to ...

Step-by-step guide on invoking a recursive function asynchronously in JavaScript

As I delved into the realm of creating a unique Omegle clone using Node.js and Socket.io for educational purposes, I encountered a challenge that has left me scratching my head. The socket ID of clients along with their interests are stored in an array of ...

Utilizing Array properties within a JavaScript class

https://i.sstatic.net/bqEZj.png I'm encountering some issues with the first property in my JavaScript class. Specifically, I'm trying to manage tokens using Firebase in a project that involves node.js and react.js. export default class NoNotifi ...

Learn how to efficiently process a data queue with AngularJS using Promises

Within my AngularJS application, I have a Service and multiple controllers running simultaneously. The app receives data updates from the server in JSON format through the Angular Service. To manage the vast amount of data, I need to queue it within the se ...

What is the best way in Angular to focus on an input field using its name, model, or id?

My goal is to create a form where, upon leaving field one (blur), the system will check if the data inputted is the word "test". If the data does not contain this word, I want the focus to return to field 1. <form name='yourForm' novalidate n ...

Error: Unable to access attributes of an undefined object (specifically 'headers') in the Next.js evaluation

I encountered an issue with next js TypeError: Cannot read properties of undefined (reading 'headers') at eval (webpack-internal:///(sc_server)/./node_modules/next/dist/server/future/route-modules/app-route/module.js:254:61) Snippet of the pro ...

unable to employ angular ui-sortable

I got the most recent source code from https://github.com/angular-ui/ui-sortable. However, I am facing issues in using it. The demo.html file seems to be broken. Update: Upon inspecting the console when opening demo.html: Navigated to https://www.google. ...

Getting the "UTC at 12:00 AM" timestamp using the java.time.Instant and ChronoUnit

How can I retrieve the UTC at Midnight Timestamp using java.time.Instant and ChronoUnit? I'm attempting to obtain the UTC at Midnight Timestamp in a specific format. For instance, if today was Feb 10, 2017, the correct date would be: Fri Feb 10 00:00 ...

``There seems to be an issue with the functionality of JSON.stringify

Upon attempting to use the JSON.stringify() method to convert an array of strings into a JSON object for passing to a PHP script, I encountered an issue where the method did not return any meaningful output. The code provided is the only one handling the ...

splitting xmlhttp.responsetext using loops

Currently, I have a JavaScript function that utilizes xmlhttp.responsetext to fetch data from MySQL. This data is then used to populate form fields in a dropdown menu, which has been functioning perfectly so far. However, the issue arises when I attempt to ...

Tips for arranging images in a horizontal layout using FlatList in React Native

Is there a way to display feed images horizontally instead of vertically in FlatList? I've tried wrapping the images in a view with flex-direction set to row, as well as adding horizontal={true} to the FlatList, but nothing seems to work. Any suggesti ...

What is the best way to separate the data of two objects within a single JSON response?

When receiving a JSON response from the server, I encountered data of two objects - one being an ArrayList Type and the other a POJO class (HomeVO). My goal is to split this data and store it into different objects. Currently, I am utilizing the GSON API ...

Master the art of navigating the Windows Sound Recorder with the power of JavaScript

I am creating a project that involves controlling the Windows sound recorder for tasks such as starting, stopping, and saving recordings. Is there a way to do this without displaying the recorder window? I would appreciate any assistance in solving this. ...

Tips to successfully utilize addEventListener on a submit action

Having issues getting this to work on submit, it functions properly when using document.getElementById("gets").addEventListener("click", b_button); but does not work when I try document.getElementById("gets").addEventListener ...

Retrieving and handling outcomes from numerous queries using jQuery's AJAX feature

Currently, I am working on making multiple ajax calls to retrieve data in json format. However, I am wondering how I can execute several queries and get the results stored in separate variables or arrays. Can someone guide me on how to structure the querie ...

Unable to show input in Javascript HTML

Every time I try to run this code on my webpage, the buttons do not seem to respond when clicked. I am aiming to have the user input for full name, date of birth, and gender displayed in the text box when the display button is clicked. When the next butt ...

Performing calculations while transferring information via Mongoose to the MongoDb database

Seeking assistance with calculating a user's BMI and storing it in my MongoDB atlas database. The BMI will be determined based on the height and weight provided by the users. I have created a Mongoose Schema to define the necessary functions, but I am ...

The initial io.emit message seems to always be delayed or lost in transmission

io.on('connection',function(socket){ console.log('connected'); socket.on('disconnect',()=>{ console.log('a user disconnected'); }); socket.on('sendMessage',function(data){ const message = data.te ...