Utilizing Vue.js to dynamically generate a table populated with elements, making API calls to fetch and display data for

I am working with a Vue component:

<template>
  <div class="tableWrapper">
    <md-table
            class="scheduledListJobList"
            v-model="scheduledList"
    >
      <md-table-row :class="item.status" slot="md-table-row" slot-scope="{item}" @click="open(item)">
        <md-table-cell class="nameColumn" md-label="Task Name" to="/upload" >{{ item.name}}</md-table-cell>
        <md-table-cell md-label="Job Number">{{ item.jobNumber }}</md-table-cell>

      </md-table-row>
    </md-table>
  </div>
</template>

<script>
import { mapState } from "vuex";
import {permissionList} from "../../permission/permission";
import {Job} from "../../api";

export default {
  name: "gg-jobs-list",

  computed: mapState(["scheduledList"]),

  mounted: function(){
    this.$store.dispatch('GET_SCHEDULED_JOBS');
  },
  data: function () {
    return {
     element: null
    };
  },

  methods: {
    open(selected) {
      this.$router.push({ path: '/jobs/' + selected.routeId});
    },
    refresh(){
      Job.getJobs()
    }
  }
};
</script>

The 'scheduledList' contains the name and id fields.

To populate the table with the 'name' field and retrieve additional information for each entry by calling a backend API, I have created a method as shown below:

  refresh(){
      Job.getJobs()
    }

  getJobs: id => getRequest(`/routes/monitoring/jobs/${id}`, null)

Each object returned by this method should include start and end fields. The goal is to update each element in the 'scheduledList' with this additional information.

If you have any suggestions or solutions on how to achieve this functionality, I would greatly appreciate your assistance. Thank you!

Answer №1

Include a new computed property with the v-model directive as its value :

 computed:{
        ...mapState(["scheduledList"]),
    scheduledListRefreshed:{
      get(){
        return this.scheduledList.map(item=>{
                 item.jobs=Job.getJobs(item.id);
                 return item;
        },
      set(val){

      }
    }

Here is how you can use it in your template :

<template>
  <div class="tableWrapper">
    <md-table
            class="scheduledListJobList"
            v-model="scheduledListRefreshed"
    >
      <md-table-row :class="item.status" slot="md-table-row" slot-scope="{item}" @click="open(item)">
        <md-table-cell class="nameColumn" md-label="Task Name" to="/upload" >{{ item.name}}</md-table-cell>
        <md-table-cell md-label="Build Number">{{ item.jobNumber }}</md-table-cell>

      </md-table-row>
    </md-table>
  </div>
</template>

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

The 'userEvent.type' function in React Testing Library is failing to update the input value in a Material UI TextField component that has

I am currently facing an issue with a material UI TextField element that is meant to track the latitude value. The requirement is for the latitude to fall within the range of -90 to 90 degrees. I have implemented a unit test as a validation measure, howeve ...

struggling with beginner-level JavaScript issues

Hey there, I've been running into a bit of an issue with my basic javascript skills: function tank(){ this.width = 50; this.length = 70; } function Person(job) { this.job = job; this.married = true; } var tank1 = tank(); console.log( ...

Navigating through a JSON object in JavaScript by employing regular expressions

Is there a way to extract the "Value" of elements "Data1", "Data2", "Data3", "Data4" from a JSON object without resorting to regex? I've heard that using regex with JSON is not recommended. <script> abc = { "model": { ... } } </script> ...

Ensuring a Memory Leak-Free Environment: Tips and Tricks

Here is my code, and I'm curious if the delete function effectively destroys an object without causing any memory leaks: class Projectile extends MovableObject{ constructor(){ super(); this.speed = 2; this.geometry = new THREE.CircleGeome ...

Retrieve the successful response data from an AJAX request

When I pull information from my MongoDB database, I receive a temporary value in the success part using $.ajax. How can I access this temp_value outside of the $.ajax function to ensure that tmp_result is set to 10? **javascript** var tmp_object = ...

Looking to implement v-model with a group of checkboxes in a Custom Component in Vue3?

The code snippet below demonstrates the power of v-model. By checking and unchecking checkboxes, the checkedNames array will automatically add or remove names. No need to manually manipulate the array with push, slice, or filter operations. const { ref ...

Checking if the current time falls within a specific time range, without taking the year into account, using Javascript

I am looking to add a special feature using JavaScript. I would like to change the background images of my webpage to ones related to Christmas during the holiday week, and have it repeat every year. How can I determine if the current date and time fall ...

Setting up Jest

I'm currently attempting to integrate the Jest Testing framework into my React Native project. Unfortunately, I am encountering an error message: Failed to retrieve mock metadata: /Users/me/Documents/Development/project/node_modules/global/window.js ...

Using React to update an existing array of objects with a new array containing objects of the same type

My issue involves an array in a class's state, referred to as A. A is populated with objects of type B through the function f in the constructor. Subsequently, I create a new array of objects of type B called C using f and new data. Upon setting the s ...

Create cookie without reloading webpage

Upon a user's initial visit to a specific page, I am displaying a jQuery overlay. The overlay includes a radio button that users can click to indicate they do not want to see the notification again. I am interested in setting a cookie to track users ...

Guide to retrieve the file name into a text box upon selection (Avoid displaying as c:/fake path/)

I am trying to achieve the functionality where after choosing a file in a file input, the file name is automatically displayed in a text box named file_name without needing to click or submit any button. Unfortunately, I have been unable to find the correc ...

JavaScript can switch the rendering mode from quirks mode to standard mode in Internet Explorer

Is it possible to switch IE from quirks mode to standard mode using JavaScript? I am unable to edit the HTML content header, and adding a new IE=edge meta tag to the head element is not effective (it displays a message stating that the mode has been set ...

How can we create a two-dimensional image with random dimensions using Math.random?

I am struggling to create a variety of flowers with different sizes from an Array. The issue I'm facing is that every time I click to add a new flower, it changes the size of all existing flowers as well. What I would like is for each added flower to ...

Unable to simultaneously execute TypeScript and nodemon

Currently, I am in the process of developing a RESTful API using Node.js, Express, and TypeScript. To facilitate this, I have already installed all the necessary dependencies, including nodemon. In my TypeScript configuration file, I made a modification to ...

Arranging HTML elements using JavaScript or jQuery

Something seems off. The sorting doesn't work as expected. Check out the JavaScript code below: function sortDescending(a, b) { var date1 = $(a).data('date'); var date2 = $(b).data('date'); return date1 > date2; } ...

The Javascript modification of an ASP.NET TextBox goes unnoticed

For someone skilled in this area, this task should be a breeze. I have three components: a launch calendar button, a continue button, and a date textbox. When the button is clicked, a JavaScript calendar pops up in a new window. This calendar sets a date ...

The initial UI did not match the server-rendered content, resulting in a Next.JS Hydration failure

I'm facing an issue with hydration in Next.JS 14, where there is a discrepancy between the server-side rendered UI and the client-side rendering. I have a suspicion that this problem may stem from using new Date(), which could be producing different v ...

Tips for displaying two dynamic variables that are interdependent

For instance: Controller: AllBooks[{ book1:{ hardcover{price:25.99},e-book{price:1.99} } }, book2:{ hardcover{price:60.00},e-book{price:2.99} }]; $scope.bookchoice = function(selectedBook) { $rootScope.choice = selectedBook;} $scope.booktype = functio ...

The submit button remains disabled even with valid form data (vee-validate)

I'm trying to implement a feature where the submit button on my form remains disabled until valid data is entered in all fields. However, even after entering correct data, the submit button stays disabled. Code Snippet: <div id="app"> <fo ...

Unable to Show the Contents of the Item - AngularJS

I'm in the process of developing an application that will showcase job details within a modal window based on the selected template. To achieve this, I've integrated ui.bootstrap and ui.router. However, I'm encountering difficulties in displ ...