Ways to retrieve information from a specific key

I'm currently facing a challenge accessing specific data objects that are referenced by keys. In this particular scenario, the "applicant" data is nested within an Event object. My goal is to extract this data and create a new object from it. While I can easily access the top-level Event data and the keys for each applicant, I'm struggling to retrieve additional details such as application date, notes, and status.

My attempted approach of using something like applicationStatus = key.status has not been successful.

onCreateApplication () {
  fb.eventsCollection.orderBy('startDate', 'desc').onSnapshot(querySnapshot => {
  let appsArray = []

  querySnapshot.forEach(doc => {
    let event = doc.data()
    let eventId = doc.data().id
    let eventTitle = doc.data().title
    let eventSlug = doc.data().slug
    let applications = doc.data().applicants
    
    // Unable to access applicant data directly
    let appStatus = doc.data().applicants.status
    
    for (var key in doc.data().applicants) {
      let eventData = {
        id: eventId,
        title: eventTitle,
        slug: eventSlug
      }
      let userData = {
        id: key
      }
      
      // Unsure how to accurately access status and appliedDate
      let application = {
        event: eventData,
        user: userData,
        status: key.status????????,
        appliedDate: key.created??????
      }
      fb.applicationsCollection.add(application)
    }

  })

  })
},

Answer №1

After looking into your data structure, I have formulated my best guess on what may be going wrong. If you need further clarification, feel free to leave a comment.

onCreateApplication(){
  fb.eventsCollection.orderBy('startDate', 'desc').onSnapshot(querySnapshot => {
    querySnapshot.forEach(doc => {
      let data = doc.data();    
      let applications = Object.keys(data.applicants).map(function(id){
        let application = {
          event: {
            id: data.id,
            title: data.title,
            slug: data.slug
          },
          user: {
            id: id
          },
          status: data.applicants[id].status,
          appliedDate: data.applicants[id].created
        })

        fb.applicationsCollection.add(application);

        return application;
      })
    })
  })
}

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

Tips for correctly implementing JavaScript conditional statements

Upon running this jQuery (1.8.3) code, I consistently receive the "in" alert message even when the length is greater than 1. The purpose of my actions is to dynamically add elements to a menu while ensuring that the element does not already exist. Even a ...

A comprehensive guide on troubleshooting the toggleComplete functionality for React Todo applications

When you click on an item in the to-do list, it should show a strikethrough to indicate completion. However, when I try clicking on an item, nothing happens. Here is my toggleComplete function and where I am attempting to implement it: class ToDoForm exten ...

Retrieve the value of a property in a JavaScript object by specifying a dynamic key for the property

As I work on my current project, I find myself immersed in a world of SVG animations. The challenge lies in triggering these animations as the user scrolls down to view the SVGs. To address this, I took the approach of creating functions for each Snap.SVG ...

Encountering an Enumeration Exception when trying to delete an element from a collection list using a foreach loop

I encountered an issue when attempting to remove an element from a list collection using foreach. I have searched online but have not found a clear explanation for the problem. If anyone has knowledge about this, please share the information. ...

Unable to retrieve a response, the operation `users.findOne()` has exceeded the buffering time limit of 10000ms

I encountered an issue when attempting to make a POST login request. The frontend is deployed on Netlify here, and the backend is deployed on Heroku here. Here are my backend logs . I am receiving `users.findOne()` buffering timed out after 10000ms in ...

Disabling the movement of arrows in the client-testimonials-carousel plugin

This plugin that I'm currently using is working flawlessly: However, I'm unsure about how to make the arrows stationary and prevent them from moving. Currently, they are centering themselves based on the height of the div, but I want them to rem ...

Notify when the SVG object is clicked based on its identifier

I'm interested in adding more complexity to this project, but before I can proceed, I need to be able to detect when a specific object element containing an SVG image with an ID is clicked. Each object is nested within a div. <div class="grid 18"&g ...

Tips on utilizing the event.preventDefault() method within AngularJS?

Recently, I stumbled upon a technique to prevent page refreshing after submitting a form by using event.preventDefault();. As someone who is still learning Angular, I am unsure of how to incorporate this syntax into my Angular controller. Is "event" some s ...

Within a single component, there are various types present when looping through an array containing objects

Hey there, I'm looking to iterate through an array containing objects with different types within a single component. operations = [ { "id": 15525205, "type": "mise_en_prep", & ...

I am eager to retrieve every single item within the categories section utilizing a Vue component

Below is my Vue component CreateProduct.vue <template> <div> <div class="row mb-4"> <label for="category" class="col-md-4 col-form-label text-md-end">Category</label> ...

What methods can I use to ensure that the data received from an AJAX request in the mounted hook is accurately displayed?

I am working on a simplified component with Vue.js <template> <div v-if="account"> <h1 v-text="accountName"></h1> </div> </template> <script> import repo from '../../repo'; expor ...

What is the best way to save and reload a canvas for future use?

My current setup involves using PDF.js to display PDF documents in a web browser. The PDF.js library utilizes canvas for rendering the PDF. I have implemented JavaScript scripts that allow users to draw lines on the canvas by double-clicking, with the opti ...

Is there a way to verify the presence of a particular value in a list?

I need to validate the content of all li tags within a ul list. If any list item contains the text "None," then I want to append specific text to a div. If no li tag includes "None," then different text should be added to the div. Upon checking my code, I ...

Developing dynamic 3D cubes

In my latest project, I am attempting to construct a unique structure composed of 3D cubes arranged in a stacked formation. Each of the individual cubes within this structure is designed to be interactive for users. When a user hovers over a cube, it trigg ...

Is it possible to dynamically append and delete rows of interconnected dropdown menus?

I'm currently working on a form that allows users to add and remove rows with cascading dropdowns for class selection. Everything is functional except for the feature to remove selected classes. I've experimented with different methods like the ...

Steps for clearing input field with type=date in Protractor:

I am currently working with protractor version 4.0.4 and I'm encountering an issue where I cannot clear a date input field. It seems like Chrome is introducing some extra controls that are causing interference. You can find further details about Chro ...

Dispatch prop within useEffect

App.js -> <Lobbies inGame={inGame} setLobby={setLobby} userName={userName} userKey={userKey}/> Lobbies.js -> import React, { useState, useEffect } from 'react'; import firebase from 'firebase'; const Lobby = ({userKey, ...

Exploring the depths of JSON using @attributes and @association in the realm of JavaScript and AngularJS

Currently, I am working on a project that involves utilizing an API for data retrieval, updates, and deletions. The API in question is the prestashop API. While I have managed to retrieve data and update certain items successfully, I encountered an issue. ...

Finding the main directory in JavaScript: a step-by-step guide

My website uses mod_rewrite to reformat the URLs like this: The issue arises when making AJAX calls to a file: I want to access login.php from the root without specifying the full URL or using the "../" method due to varying folder levels. So, I need a ...

"Exploring the concept of Undefined in Javascript Arrays

I keep encountering the issue links[i] is undefined. Even after explicitly defining it, the error persists. Any thoughts on why this might be happening? I am attempting to implement unobtrusive image rollovers for 5 links that I currently have. function ...