"Learn how to implement a dropdown menu using Vue.js and Quasar on Cloud Firebase

Hey there, I'm trying to figure out how to retrieve and display a Firebase array in a dropdown using Vue js. Here's what I currently have:

I've read some of your articles before, but I'm having trouble displaying the data from an array. I'm not sure how to edit them to add more data, but my main goal is to show the data retrieved from Firebase in a dropdown menu.

<template>
  <div class="q-pa-md">
    <div class="q-gutter-md row items-start">
      <label>labs</label>
      <input v-model="laboratorios" type="text" class="form-control" />
      <q-btn color="primary" @click="guardarLab()" label="Primary" />
      <q-select
        filled
        multiple
        clearable
        use-input
        use-chips
        option-label="laboratorios"
        v-model="lab"
        :options="labs"
        style="width: 250px"
      />
      <!-- <select v-model="lab">
        <option v-for="(item, index) in labs" :key="index" v-html="item.laboratorios"></option>
      </select>-->
    </div>
  </div>
</template>

<script>
import { db } from "boot/firebase"; // don't forget to import db
export default {
  data() {
    return {
      laboratorios: "",
      nombre: null,
      lab: null,
      multiple: null,
      labs: []
    };
  },
  created() {
    this.getLabData();
  },
  methods: {
    // retrieving lab data from Firebase
    async getLabData() {
      try {
        const dbData = await db.collection("laboratorios").get();
        dbData.forEach(data => {
          console.log(data.id);
          const labData = { laboratorios: data.data().laboratorios };
          this.labs.push(labData);
        });
      } catch (error) {
        console.log(error);
      }
    },
    // saving lab data
    saveLab() {
      var labInfo = { laboratorios: this.laboratorios };
      this.labs.push(labInfo);
    }
  }
};
</script>

At the end, I'm encountering this issue: enter image description here. In my Cloud Firestore database, I have this data: enter image description here

Answer №1

To resolve the issue, make sure you are passing individual laboratorios rather than arrays. Update your code as follows:

GUI:

<select v-model="lab">
    <option :value = "labItem" v-for = "labItem in labs">{{labItem}}</option>
</select>

Data:

created(){
    // Listen for real-time updates
    db.collection("laboratorios").onSnapshot(labs=>{
        // Combine arrays of each document into one and assign it to Vue data
        this.labs = labs.docs.reduce((x,y)=>{
            return x.concat(y.data().laboratorios);
        }, [])
    })
}

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

Retrieve an array from the success function of a jQuery AJAX call

After successfully reading an rss file using the jQuery ajax function, I created the array function mycarousel_itemList in which I stored items by pushing them. However, when I tried to use this array in another function that I had created, I encountered t ...

Using jQuery to evaluate multiple conditions within an if statement

I'm working on a script that needs to continuously monitor for the presence of an input field with the class name "email" (as this content is loaded via AJAX). If this input exists, I need to show another input field with the class name of "upload". A ...

Tips for hovering over a link with Webdriver

Currently, for my project, I am utilizing Selenium Webdriver. Successfully automating the functionality to mouse over an image has been achieved. However, there seems to be an issue when attempting to trigger a mouse-over event on a hyperlink using the sam ...

Evaluation of Library (VueJS) - Displaying various components in an individual test case

Just starting out with testing and have a simple question: I am working on testing a checkbox component. I understand the basics, but how can I render multiple components within one it block? Here is my current code. I am stuck on the second test where I ...

Tips for adjusting the time interval on an automatic slideshow when manual controls are in play

I'm having trouble with my slideshow. I want it to run automatically and also have manual controls, but there are some issues. When I try to manually control the slides, it takes me to the wrong slide and messes up the timing for the next few slides. ...

Installing different versions of a package in npm can be done by loading multiple versions

I am in the process of setting up a web API and I want to provide support for various versions of the underlying library. In essence, I would like to access it through: where x.y.z represents the version of the library I am utilizing. Using npm for mana ...

jquery module for retrieving and updating messages

I want to develop a custom plugin that can be utilized in a manner similar to the following example. This isn't exactly how I plan to use it, but it serves as the initial test for me to fully grasp its functionality. HTML: <div id="myDiv">< ...

At what point are watch variables accessible in the Chrome-Node-Debugger tool?

My test file runs periodically, either every minute or second, depending on how I configure it. https://i.sstatic.net/duXl5.png Despite setting watches on variables in the file, they do not populate as expected: https://i.sstatic.net/W6CFo.png Interest ...

Using JSON Values in JavaScript

Below is a JSON result structured like this : [{"Januari":"0","Februari":"0","Maret":"0","April":"0","Mei":"7","Juni":"0","Juli":"0","Agustus":"0","September":"0","Oktober":"0","November":"0","Desember":"0"}] What is the best method to input these values ...

What steps should I take to ensure axios is returning the appropriate buffer type?

Upon initially posting this question, I was completely lost on where to even begin or how to appropriately title it. With the assistance of multiple comments, I enhanced the data provided and finally settled on the current question title - a big thank you ...

How can I efficiently transfer a JavaScript array to a PHP script using the GET method?

My web application is designed with jQuery allowing users to manipulate visual elements. The next step is sending the JavaScript object state to PHP for storage in a database. While I prefer using GET, I am open to solutions that involve POST submission as ...

Tips for identifying the cause of a memory leak in browser notifications

I am looking to implement browser notifications in a browser extension. However, I have noticed that the memory usage does not decrease after closing the notification. Can someone explain why this may be happening? Allow StackOverflow show notifications i ...

leaflet.js - Place a marker when clicked and update its position while dragging

Currently working on a small project that requires the ability to place a marker on an image-map powered by leaflet.js, and update its position if it's dragged. I was using the code below for this functionality but keep getting an error 'marker n ...

Using jQuery to toggle the visibility of table data cells across various tables on a single webpage

On my webpage, I have multiple tables and I'm trying to add more rows or close table data cells using jQuery. However, I seem to be encountering an issue as it's not working properly. <table class="table" ><tr> < ...

We were unable to locate the requested resource

I have been working on setting up an Express endpoint to fetch comments or reviews of a movie based on the movie ID. In my initial route, I manually passed the ID and retrieved data from TheMovieDB. However, I wanted to make this process dynamic in my seco ...

How can I transfer the total and counter values to a different PHP page and store them in a text box before saving them to the database?

I need to transfer the total and counter values to another PHP page using a text box and then save them to a database. { var price =10; //price $(document).ready(function() { var $cart = $('#selected-seats'), //Sitting Are ...

Correlating Mailgun Webhook event with Mailing list email

Recently, I have started using the Mailgun API to send emails and have also begun utilizing their mailing list feature. When sending to a mailing list, such as [email protected], I receive a single message ID. However, when receiving webhook responses, t ...

Creating an array of objects data is a breeze with Vue.js

I have an array of data containing selected items, and I need to extract the IDs from this array into a new array so that I can send only the IDs to the back-end. Sample Code method toggleSelection(rows) { console.log('this.multipleSelection : &a ...

Is there a way to merge these arrays into a single array?

With the current code I am obtaining numerous JSON objects within separate arrays: Here is the code snippet: for (let i=1; i<=150;i++){ fetch(`A valid URL ${i}`) .then(result => result.json()) .then(result => console.log(result.data.results)) ...

Utilizing React Native to Query, Filter, and Save a Single Document Field Value from Firestore Database into a Variable/Constant

My current task involves setting up a Firebase Firestore Database in order to filter it based on a specific field value within a document. The collection I am working with is named "PRD" and consists of thousands of documents, each sharing the same set of ...