Using Vue JS to showcase array data in a dropdown menu with Bootstrap-vue

Currently, I have an array of JSON data structured like this:

 loggers = [{
        "allAvailableLevel": ['WARN', 'DEBUG', 'INFO'],
        "level": "WARN",
        "logger": "com.test1",
        "status": "success"
    },
{
        "allAvailableLevel": ['WARN', 'DEBUG', 'INFO'],
        "level": "WARN",
        "logger": "com.test2",
        "status": "success"
    }
    ]

Within my code, there is a table column that includes a dropdown element. However, despite traversing the Loggers array, I am struggling to extract and display the allAvailableLevel data.

 <table class="table table-bordered">
        <thead>
          <tr>
            <th>#</th>
            <th>Class</th>
            <th>Current Level</th>
            <th>All Available Levels</th>
            <!-- Only display "Action" header if level is changed-->
            <th>
              Action
            </th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(logger, index) in loggers" :key="logger">
            <td>{{ index + 1 }}</td>
            <td>{{ logger.logger }}</td>
            <td>{{ logger.level }}</td>
            <td>
              <b-dropdown
                boundary="viewport"
                id="dropdown-dropup"
                size="sm"
                :text="selectedLevelText"
                split
                class="m-2"
              >
                <b-dropdown-item-button
                  v-for="logger in loggers[0].allLevel"
                  :key="logger"
                  @click.prevent="changeLevel(level)"
                  >{{ logger }}</b-dropdown-item-button
                >
              </b-dropdown>
            </td>
            <td v-if="levelChanged">
              <b-button
                size="sm"
                variant="secondary "
                @click.prevent="updateLevel(selectedLevelText)"
                >Update</b-button
              >
            </td>
          </tr>
        </tbody>
      </table>

After implementing the above code, the appearance of my dropdown now resembles the following:

https://i.sstatic.net/x4PM6.png

However, I am aiming for a layout similar to this one:

https://i.sstatic.net/A97B5.png

Any suggestions on how to effectively traverse the data inside the vue template to specifically retrieve the data related to "allAvailableLevel"?

https://i.sstatic.net/A97B5.png

Answer №1

To properly loop through the nested array, use the following code:

< b-dropdown-item-button
                      v-for="level in logger.allAvailableLevel"
                      :key="level"
                      @click.prevent="changeLevel(level)"
                      >{{ level }}</b-dropdown-item-button
                    >

Answer №2

Follow these instructions:

<tr v-for="(user, position) in usersArray" :key="logger">
  <td>{{ position + 1 }}</td>
  ...
  <td>
    <b-dropdown
      boundary="viewport"
      id="dropdown-dropup"
      size="sm"
      :text="selectedUserText"
      split
      class="m-2"
    >
      <b-dropdown-item-button
        v-for="level in user.allAvailableLevels"
        :key="level"
        @click.stop="updateLevel(level)"
        >{{ user }}</b-dropdown-item-button
      >
    </b-dropdown>
  </td>
</tr>

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

JavaScript pop-up that appears across all applications

An ASP.NET page I've developed in IE is responsible for monitoring multiple server jobs that run overnight. Whenever an error occurs on one of these jobs, a popup window opens using javascript's window.open() function. However, employees often ha ...

Leverage a custom server (such as NestJS) within NextJS to dynamically render targeted pages

I am experimenting with using NestJS as a custom server for NextJS, following the instructions in this article. Here is a simplified version of the code: @Controller('/') export class ViewController { @Get('*') async static(@Req() r ...

Is it possible to increment an integer value in jQuery after obtaining the sum result?

Actually, I'm trying to extract the integer value from my input field. For example, if I enter the value 4+5, I want to display the result as 9 in a separate div. However, instead of getting the expected result, I am receiving [object Object]. I&apo ...

Combining two objects retrieved using ngResource in AngularJS

Seeking guidance on merging two objects retrieved using ngressource. Every 5 seconds, I invoke my service to fetch a message and aim to append the new message with the older ones. The JSON message I receive: [ {"age": 0,"id": "my first tweet","name": "H ...

What is the best way to integrate JavaScript libraries into my NPM build process?

My current website is built using HTML and CSS (with SCSS) and I have been using an NPM build script. Now, I am looking to incorporate some JavaScript libraries into my site, such as lozad. I have already downloaded the necessary dependencies for the libr ...

What methods can I use to evaluate the efficiency of my website?

Is there a way to assess and improve website performance in terms of load time, render time, and overall efficiency? I've heard of YSLOW for firebug, but am curious if there are any other tools or websites available for this purpose. ...

Strategies for managing large numbers within WebGL GLSL shader programs

What is the best approach to handle large numbers like the one provided in GLSL? I have a shader that requires Date.now() as a uniform, which is defined as: The Date.now() method returns the number of milliseconds elapsed since January 1, 1970 00:00:00 ...

The AJAX call was successful, however, the response did not contain any data

I have a MySQL table where I use a FOR EACH loop to display data on my page. I then make an AJAX request to update the displayed data every time a new row is inserted into the database. Although the AJAX request is successful, it returns empty data. I&apo ...

Find and Scroll Dropdown Menu with Bootstrap Framework

Access the jsfiddle for more information. Have a look at these questions: In my dropdown menu, I have included a search box and multiple sub-menus. However, the search box only filters the first dropdown menu and does not work with the sub-menus. How ca ...

Extracting live TV channels from an m3u file by differentiating them from VOD content

Currently, I am developing an IPTV player app and have successfully parsed the m3u file. My current challenge is separating live TV channels from Video on Demand (VOD). I am unsure of where exactly the transition happens in the playlists. Below are the ke ...

Encountering difficulties with properly storing an array in MongoDB using Node.js and Mongoose

Can you point me in the right direction on how to properly store an array of data in mongodb using node/mongoose? I'm currently facing an issue where all my data is being saved as the first value in the array. Here's a snippet of my code: const ...

Console displays 'undefined' when using the post method with Node.js/Express

Below is the code for my upload.ejs page: <%- include('header' ,{ title:"Playground" }) -%> <div class="wrapper"> <form action="/upload" method="POST" enctype="multipart/form-data"> <input type="text" name="name" place ...

How can you conceal an object based on specific conditions in JavaScript?

In my JavaScript code, I am working with an object that stores multiple values. However, I want to be able to hide a specific object under certain conditions. Here is the data structure: $scope.sort={ National : { prop: "Country", classes: { md: ...

Looking to add a dynamic divider between two columns that can be adjusted in width by moving the mouse left and right?

If you're looking for an example of two columns adjusting their width based on mouse movement, check out this page from W3Schools. I'm trying to implement this feature in my React app, but I'm unsure of how to proceed. Below is the JSX code ...

What is the best way to modify a variable's value from a nested controller and vice versa?

There seems to be an issue with changing the 'mensaje' variable in both the "padre controller" and the "hijo controller" and visualizing the changes. When clicking on "cambiar padre," the value changes as expected. However, if I then click on "ca ...

Retrieve the array element that is larger than the specified number, along with its adjacent index

Consider the following object: const myObject = { 1: 10, 2: 20, 3: 30, 4: 40, 5: 50, }; Suppose we also have a number, let's say 25. Now, I want to iterate over the myObject using Object.entries(myObject), and obtain a specific result. For ...

The issue with mapDispathToProps is that it is failing to assign a function

import React, { Component } from "react"; import PropTypes from "prop-types"; import { connect } from "react-redux"; import { ShelfModal } from "./shelf-modal"; import { openShelfModal } from "../../../redux/actions/shelf-modal"; export class ShelfTest ex ...

Using eslint with the vue plugin allows you to specify which object fields to ignore in

My ESLint rule setup includes the following: "vue/script-indent": [ "error", 4, { "baseIndent": 1, "switchCase": 1, "ignores": [ "[init.type=\"ObjectExpression\"]", "[init.type= ...

React Native error - "Invalid element type: expected a string or class/function, but received undefined" - encountering issue with importing a custom library?

Alright, I'm looking to make some modifications to this library, so I am attempting to import the non-transpiled version by downloading the repository and importing it from here: https://github.com/nicotroia/react-native-floating-action-menu#readme A ...

Ways to attribute a numeric worth to a choice in a JavaScript form

I am in the process of creating a form that allows users to customize and order pizza while showing them the invoice as they make their selections. Currently, I have successfully implemented the display of user-selected options, but I am struggling with a ...