Exploring the Depths: A Guide to Displaying Nested Databases with Vue.js and Firebase

Here's my first question on this platform because I'm feeling a bit overwhelmed. I've been experimenting with firebase and vue.js, attempting to navigate through my key-value database construct.

Below is the JSON data I exported:

{  
   "city":{  
      "new york":{  
         "zipcode":{  
            "10039":{  
               "street":{  
                  "W 152nd St":[  
                     "263",
                     "250",
                     "21"
                  ]
               }
            },
            "02116":{  
               "street":{  
                  "W 155nd St":[  
                     "3",
                     "25",
                     "21"
                  ]
               }
            }
         }
      },
      "boston":{  
         "zipcode":{  
            "02116":{  
               "street":{  
                  "Berkeley St":[  
                     "161",
                     "65",
                     "13"
                  ]
               }
            }
         }
      }
   }
}

I was hoping to create a dependent dropdown structure like [city [v]] [zipcode [v]] [street [v]] [number [v]]. Any advice or suggestions would be greatly appreciated.

Thank you in advance for taking the time to help me out!

Edit:

<div v-for="location in test">
    <div v-for="(address,city) in location">
        <div v-for="(nextplz,plzLabel) in address">
            <div v-for="(nextstreet,plz) in nextplz">
                <div v-for="(streetInfo,streetLabel) in nextstreet">
                    <div v-for="(numbers,streetName) in streetInfo">
                        {{location['.key']}} : {{city}}<br/>
                        {{plzLabel}} : {{plz}}<br/>
                        {{streetLabel}} : {{streetName}}<br/>
                        {{numbers}}<hr/>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

Edit-2: Corrected indentations and typos in JSON

Answer №1

Assuming that the variable test represents an array of location objects, each resembling the JSON structure you provided. When iterating through arrays in Vue.js, the common practice is to use the v-for directive. In order to access properties within objects, use dot notation. You can achieve this by writing the following code:

<div v-for="location in test">
  {{location.address.nextplz.nextstreet.streetInfo}}
  {{location.address.plzLabel}}
</div>

If you wish to cycle through all cities and display related information, you can accomplish it with the following approach:

<div v-for="location in test">
  <div v-for="(key,val) in location.city">
    <!-- Display detailed info about zip code for each city -->
    <pre>{{city[key].zipcode}}</pre>
  </div>
</div>

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

I'm looking for guidance on the syntax of declaring a constant variable with an empty object in JavaScript. Can someone please explain or

Can you explain the meaning of this JavaScript syntax (likely in ES6)? const {} = variablename; I've been diving into React lately and noticed this syntax used in many examples. For instance: const {girls, guys, women, men} = state; ...

The construction of the Gatsby site encountered a major obstacle

I've been facing challenges while trying to build my Gatsby site. Whenever I run 'gatsby develop' in the console, my app starts without any issues. However, when I attempt to build it, I encounter errors like the ones shown below. Does anyon ...

React.js router - struggles to clean up unsightly query parameters in the URL

I've been trying to eliminate the query string by following this solution: var { Router, Route, IndexRoute, IndexLink, Link } = ReactRouter; var createHashHistory = History.createHashHistory; var history = createHashHistory({queryKey: false} ...

Update the formatting of the dates in the dateRangePicker

Utilizing a dateRangePicker, I am receiving dates in the format "mm-dd-yyyy". Below is my HTML code: <input type="text" name="TextDate" value="10/24/1984" /> Here is the script being used: <script> $(function() { $(&apos ...

Can you please point out the location of the error in the Java Script code

Our application is developed using Yii2 framework and incorporates Kartik's star-rating widget. However, there seems to be an error in the JavaScript code: Error message from console: Check out the problematic code snippet: <?php $js = ...

Exploring JavaScript-based navigation with Python and Selenium

Here is the URL of the page in question: link. I am trying to navigate pagination with the following HTML markup: <li class="btn-next"> <a href="javascript:ctrl.set_pageReload(2)">Next</a></li> I have written a ...

Sometimes Google Maps API doesn't load properly on my page until I hit the refresh button

Occasionally, I encounter a problem where my Google Map fails to load when the webpage is first opened, resulting in a blank map. However, upon refreshing the page, the map loads correctly. The error message appearing in the Chrome console reads as follow ...

Is it possible to verify that a string exclusively comprises elements from an array?

Hey there, I've got a challenge where I need to verify whether a string consists only of letters from a predefined alphabet. If not, my bot kicks players from the game. I've come up with the following script: var letters = "a b c d e f g ...

What is the best way to substitute spaces with underscores in JSON data and incorporate hyperlinks for each row in datatables?

I am looking to customize JSON data from the back-end before displaying it using datatables. Firstly, I want to replace the spaces ( ) in the column artist.name with underscore symbols (_). Additionally, I would like to create hyperlinks for each row in th ...

Has anybody managed to successfully implement this require or debug NPM module for use in a web browser?

Has anyone successfully implemented the require or debug NPM modules in a browser environment? Despite claims and instructions on the debug NPM module's page that it can be used in the browser, attempting to do so results in the following error: Unc ...

Adjusting the minimum value on a textfield with JQuery Validate plugin in real-time

I am attempting to dynamically update the minimum value on one field based on input from other fields. Here is a brief overview of my code: $("#new_project").on("click", function() { switch($('input:radio[name=quality-level]:checked').val() ...

Tips for creating a unique exception in AngularJS?

I have a customException.js script with the following service: app.service('CustomException', function() { this.CustomException1 = function (message) { if (!message) { message = "Custom Exception 1 occurred!"; } return { ...

I'm having trouble with populating data in Mongoose. Can anyone provide guidance on

I am currently working on a simple CRUD example for a larger open-source project. I'm trying to populate user data, but despite consulting documentation and forums, I haven't been able to resolve the issue that's causing trouble. The error ...

Adjust the size of an IFRAME to eliminate scrollbars from appearing

My webpage features an iframe that needs to be resized dynamically each time its contents change in order to eliminate scrollbars. The content inside the iframe frequently changes without altering the URL. I desire for all the content within the frame to b ...

Explain the inner workings of the setTimeout() function in JavaScript

My goal is to create a line in my code by placing points according to the line equation and adding a 100 millisecond delay before each point is displayed. However, when I try to run the code, it seems to wait for some time and then displays all the points ...

The mystery behind the enigmatic combination of ajax, JQuery,

Seeking Assistance! All fields are displaying undefined values function UpdateData(){ var id = $('#id').attr('value'); var name = $('#name').attr('value'); var department = $('#departament'). ...

What is the best method for packaging a React component library?

Currently, I am working on developing a React component library that I aim to distribute via npm to reach a wide audience. In my development process, I utilize webpack and babel for packaging and code processing. However, as a newcomer to webpack, I am uns ...

Difficulty encountered in resetting progress bar post ajax form submission

Hello, I hope you can assist me with an issue I am facing regarding my progress bar. After submitting the form using AJAX to insert data, my progress bar does not reset. I would like it to reset after clicking the submit button. The progress bar is speci ...

Tips for inserting a hyperlink on every row in Vuetables using VUE.JS

Trying to implement a link structure within each row in VUEJS Vuetables has been challenging for me. Despite my research on components and slots, I am struggling to add a link with the desired structure as shown below: <td class="text-center"> <a ...

What is the best way to route a localpath to a different page including parameters in Nuxt Js?

Hello, I am facing an issue where I need to pass parameters in the URL to another page in NuxtJs props: { idPending: { type: Number, required: true } }, methods: { fetchpage() { const orderId = this.idPending; this.$rou ...