Vue.JS patiently anticipating the completion of a for loop within a watched property

My application must perform multiple API calls in a specific sequence.

The allMeetings function should be executed first, followed by pastMeetingsUUIDs. The goal is to ensure that the for-loop inside allMeetings finishes before pastMeetingsUUIDs is triggered to avoid making unnecessary API calls.

Currently, whenever pastMeetingUUIDs is updated, the function pastMeetingUUID fires as expected. However, I want it to only execute once after the for loop has completed.


watch: {

  allMeetings: function (){
    for (var i = 0; i < this.flatAllMeetings.length; i++){
         getPastMeetingUUIDByID(this.flatAllMeetings[i].id).then( data=> this.pastMeetingUUIDs.push(data.data))
       }
     this.allMeetingStatus = true
     }

  },

   pastMeetingUUIDs: function () {
   if(this.allMeetingStatus == true){

 //response is a mixed object array
      const entries = Object.entries(this.pastMeetingUUIDs)
      entries.forEach(element => {

        element[1].meetings.forEach(element =>{
            getPastMeetingParticipants(element.uuid).then(data=> console.log(data))
        })
      })
   }
}
 },

Despite the code structure, the current implementation still loops through the pastMeetingsUUID array multiple times, which is unclear why it happens.

Answer №1

retrieveAllMeetings: async function (){
    const meetingsIDs = []
    for (var i = 0; i <this.flatAllMeetings.length; i++) {
       const meetingData = await fetchMeetingDataByID(this.flatAllMeetings[i].id)
       meetingsIDs.push(meetingData.data)
    }
    Array.prototype.push.apply(this.meetingsData, meetingsIDs);
    this.allMeetingsRetrieved = true
}

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 aria-label attribute is not compatible with the Android Chrome browser when used on an input

Have you noticed that aria-label is not being read correctly on Android Chrome? For example: <input aria-label="test" type="text"> When using Android chrome, it reads "Editbox, double tap to edit, double tap to enter text". However, when using iOS ...

How to Conceal the Search Bar in jQuery DataTables

I am having trouble hiding the default search bar in DataTables. Despite trying solutions from this thread, using bFilter:false completely disables filtering, rendering my search boxes in the footer non-functional. I have created a jsfiddle demonstration. ...

What causes the modal to appear and then vanish suddenly?

I've created a simple modal code with minimal JS involved. When the button is clicked, the modal appears briefly, then the page refreshes and the modal disappears. I'm not sure what could be causing this issue. Any help would be appreciated! h ...

What is the method for incorporating an onmouseover event into child states while extending the parent state controller?

I have a basic angularjs controller coupled with jquery that triggers a console log message when the mouse hovers over an anchor element: app.controller('MenuController', function() { $("a").on('mouseover', function (e) { c ...

Encountering a ReactJS error when retrieving an object assigned from an axios call to an

The code snippet below is causing me some confusion: import React, { Component } from 'react'; import axios from 'axios'; class Dashboard extends Component { state = { name : 'randomname', apiData: {} ...

Modify the background of a div according to the size of the screen. Implement this functionality using JavaScript and

After reviewing a specific post at , I find myself unsure of how to target a particular class for reference. I am certain that I want to implement document.onload = checkWidth(); window.onresize = checkWidth(); However, I am uncertain about the procedur ...

Guide on effectively exporting an NPM module for all browsers:

I have developed an NPM module which looks like this: class MyModule { // code here }; I am interested in making the export of MyModule universal, so that users can easily import it using any of the top 3 popular methods in the Browser: Using ES6 I ...

The integration of angular 1.3.15 with html5mode for deeplinking, routing, and hash functionality

I have implemented html5mode true and included <base href="/"> within the head tag. Everything appears to be functioning properly at first, but upon page refresh, an error is encountered. The requested URL /updated_1/work was not found on t ...

Examining the disparity between two dates through mocha/chai testing

I am currently utilizing "chai": "^4.2.0" and "mocha": "^6.1.4",. Upon using assert.equal() to compare two dates, I encounter a discrepancy where the comparison returns false despite the dates appearing the same. Here is an example of the situation: http ...

Is it possible to enable selection functionality for WebGL text geometry once it has been integrated into the viewer's scene?

Upon adding a text geometry object to the viewer, I realized that I am unable to select it with the mouse as I can with other objects in the viewer. How can I make this text selectable? I have not attempted any solutions yet, as the documentation does not ...

Filtering data from MongoDB within the controller logic

I have a query in my controller that retrieves records from a MongoDB document. However, I need to filter the incoming records by a field archived == true. The current code works fine without any filters. I'm trying to figure out where to add the fil ...

Insert the video link and preview it with live option

Currently working on a form that allows users to input a video URL. The form will be a standard input field where they can enter a URL such as: http://video.google.com/videoplay?docid=1299927595688205543 I want to include a button within the form labeled ...

Using V-for to loop through a list of items, with a unique twist thrown in

I've successfully used v-for to display an array in a single line, but I want to add commas between each word. The issue is that adding a comma at the end results in an extra comma. Any ideas on how to tackle this? ...

Changing the color of dots in a React Material-UI timeline

Hey there, I'm trying to change the default color of the MUI TimelineDot component. I attempted to do so by adding this code: <TimelineDot sx={{ '& .MuiTimelineDot-root': { backgroundColor: '#00FF00' }, }} /> Unfortunate ...

Generating a dynamic triangle within a div while ensuring it fits perfectly with the maximum width

I need help with creating a responsive triangle on a web page that takes three inputs. The challenge is to adjust the size of the triangle so it fits inside a div element while maintaining the aspect ratio of the inputs. For instance, if the inputs are 500 ...

The data provided is not in the correct format for a timestamp

Currently, I am utilizing the pg node module to establish a connection with PostgreSQL, and I have been attempting to run the following query: const res = await client.query(`SELECT number_transactions FROM transaction.city_unique_dates WHERE date_day_t ...

What Makes Bootstrap Spinner Ineffective in High-Performance Computing Scenarios

I understand that Javascript operates on a single thread, but I am puzzled as to why the spinner is not showing or hiding before/after a compute-intensive task in the following code. Here is the outline of the code: showSpinner(); computeIntensiveTask(); ...

Display the execution duration on an HTML document

Recently, I created a loan calculator using Javascript and now I'm contemplating on incorporating the time taken for the code to execute into the results. My intention is to have the execution time displayed on my HTML page, but I am unsure of how to ...

Exploring JavaScript capabilities with Google - managing and updating object names with numbers

After importing JSON data into Google Scripts, I am able to access various objects using the code snippet below: var doc = Utilities.jsonParse(txt); For most objects, I can easily retrieve specific properties like this... var date = doc.data1.dateTime; ...

What is the best way to ensure that the bootstrap nav tab content fits perfectly on one line?

Check out this bootstrap navbar example You can see a screenshot here. <ul class="nav nav-tabs" style="display: inlne-block"> <li class="nav-item" style="text-align: center; display: inline;"> <div> <a class="nav ...