0

I have my firebase DB with this tree structure.

enter image description here

I use vue-fire to loop through the database. I want to retrieve the "CantFindMe" value in the name property. My files look like this:

// Dashboard.vue
<template>

<div class="">
  <ul>
    <li v-for="personName in names" v-bind:key="personName['.key']">
      <div v-if="!personName.edit">

        <p>{{ personName.forms.step1 }}</p>

        </div>
    </li>
    </ul>
</div>
</template>

<script>

import { namesRef} from '../firebase.js'

export default {
  name: 'app',
  data () {
    return {
      name: ''
    }
  },
  firebase: {
    names:  namesRef
  }
}
</script>

// Firebase.js

  { The usual firebase config }
  {...}
  export const firebaseApp = firebase.initializeApp(config)
  export const db = firebaseApp.database()
  export const namesRef = db.ref('names') 

I manage to read the object: { "-KxrySGBHgLvw_lPPdRA": { "edit": false, "name": "CantFindMe" } }

But when I try to add ".name" after ".step1", that should supposedly return "CantFindMe", I get nothing/blank back.

How do I get to the name property using VueJs to return "CantFindMe"?

1
  • You are missing some required steps in process of getting data from Firebase realtime database. Wait for hour, I create new Fbase project and provide you working example in answer. Commented Nov 2, 2017 at 9:32

1 Answer 1

2

Sorry for delay, Im not using vuefire... So, first - do not refer to names only, but directly to step1:

export const namesRef = db.ref('names/EcoClim/forms/step1/')

You will obtain structure like this:

[{
  ".key": "-KxrySGBHgLvw_lPPdRA",
  "edit": "false",
  "name": "CantFindMe"
},  {
  ...
}]

Now you can use it in template, but as key, refer to array index and not to FBase key:

<li v-for="(person, idx) in names" :key="idx">
  <div v-if="!person.edit">
    <p>{{ person.name }}</p>
  </div>
</li>
Sign up to request clarification or add additional context in comments.

3 Comments

@WaldermarIce Its works!!! Nice! But it also works without binding of the key. Why is that?
@TonyRositano Key is not always necessary. But, is recommended for every v-for directive however. PS: please accept my answer. You know ... reputation is important :)
@TonyRositano Thax :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.