Vuefire: Accessing .key values

Created on 21 Oct 2016  路  4Comments  路  Source: vuejs/vuefire

What is the syntax to get a data value's .key value? Neither {{ obj.key }} nor {{ obj.'.key' }} work for me.

Most helpful comment

@PedroFelipe In your example the key value will be the number (position) of the array and not the value of the .key item. In that case you need to use the method that @romines mention. Using your example it will be something like: {{ item['.key'] }}

All 4 comments

To retrieve the key when you have a reference to the object, try obj['.key']

I am having trouble referencing the firebase item after I have determined the key.

From inside the component where the ref is setup, this.$firebaseRefs.myRoot.child(key) seems like it should work, but no luck so far. It gives me back something that looks like this:

screen shot 2016-10-21 at 12 06 14 am

It's what @romines said
If you can share some code I may help you. Ideally a repro on a fiddle would make things faster

try this:
v-for="(item, key) in items"

and {{ key }} 馃憤

@PedroFelipe In your example the key value will be the number (position) of the array and not the value of the .key item. In that case you need to use the method that @romines mention. Using your example it will be something like: {{ item['.key'] }}

Was this page helpful?
0 / 5 - 0 ratings