2016-04-11 17 views
0

Burada Firebase almak istediğiniz nesnenin bir ekran görüntüsü var. ReactJS - firebase nasıl özel bir sorgu sorgulama .key

enter image description here

Bu

Ben

constructor(){ 
    super(); 
    this.state = { 
     items: [] 
    }; 
} 
componentWillMount(){ 
    this.firebaseRef = new Firebase('https://sweltering-heat-7923.firebaseio.com/contact/-KF1XUgOvcrybku8Q52s'); 
    this.firebaseRef.once("value", function (snapshot){ 

     snapshot.forEach(function(data){ 
      console.log(data.val()); 
     }.bind(this)); 
    }.bind(this)); 
} 

ben bu yanıtı

Ben bu

gibi bir şey bekliyordum, ne istediğini değil

enter image description here

var böyle yaparız

{ 
    object{ address1: '', address2: '', postalCode: ''} 
    email: "", 
    firstName:"ohoh", 
    gender:"", 
    id:1460331472003, 
    lastName: "asd", 
    phone: "" 
} 

Nasıl yapardınız?

+0

https://www.firebase.com/docs/web/guide/retrieving-data.html bakın. – Kato

cevap

2

contact/-KF1XUgOvcrybku8Q52s tüm çocuk düğümleri üzerinde yineleme yapıyor ve bunları tek tek kaydediyorsunuz. Tam nesneyi almak için snapshot.forEach(...) yerine snapshot.val() kullanın:

this.firebaseRef.once('value', function(snapshot){ 
    console.log(snapshot.val()); 
});