arrays - How to get the key of a Firebase Object -


how can key of firebase object without using snapshot?

i have done research below.

using code:

var ref = new firebase('https://johnsoncompany.firebaseio.com/people')  var firstperson = ref.orderbychild("first").limittofirst(1);  var key = $firebaseobject(firstperson); 

..i object below:

{      "5":{         "first":"jennifer",       "last":"robert",       "mobile":"121 364 135",    } } 

firebase had given object key "5" since data contained in array of values. 6th value.

the challenge in-order value "jennifer", have know key "5".

i use code:

var firstperson = $firebaseobject(ref.child('5'))  var firstname = firstperson.first; //returns jennifer 

i know can use code below key '5':

    ref.orderbychild("first").limittofirst(1).once("child_added", function(snapshot) {         alert(snapshot.key());     });  

the challenge there delay before returns key. results malfuctioning app.

is there way can key without snapshot

ref.orderbychild("first").limittofirst(1).key(); //this doesn't work 

i know might have found solution issue now, here use retrieve key of object. use same key run query (filter).

itemsref.on('value', (snap) => {   var items = [];   snap.foreach((child) => {     items.push({       active: child.val().active,       profile: child.val().profile,       image: child.val().image,       description: child.val().description,       title: child.val().title,       _key:child.key, //<--------------this key     });   });   this.setstate({     datasource: this.state.datasource.clonewithrows(items),   }); }); 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -