2017-11-01 2 views
0

ためfirebaseからのデータを複数のデータを取得する「ノンブル、RFC、infGen、ubicacion」リアルタイムの参照構文があなたを投げている場合javascriptの私は、データ <p></p>この方法で印刷できるようにするには、コンソールにデータを印刷カントには、ホテルからすべてのデータを取得できますか

My database

+0

することにより、データ1を取得し、必要な操作です。 –

+0

私はドキュメントを読んでいますが、私はどのようにリストを取得することができますか?()()()データを収集し、最初の機能で – Montero

+0

の結果を管理すると、変数snapshotはfirebaseクエリ応答です。 snapshot.val()は、 –

答えて

0

foreachのは、これはあなたの質問への答えはfirebaseのドキュメントにある1

var query = firebase.database().ref("Hotel/"+usuario.uid); 
     query.once("value") 
      .then(function(snapshot) { 
      snapshot.forEach(function(childSnapshot) { 
       var hrfc = childSnapshot.val().RFC; 
       var hnombre = childSnapshot.val().nombre; 
       var hinfo = childSnapshot.val().infoGen; 
       var hubic = childSnapshot.val().ubicacion; 


      }); 
     }); 

}

0

またFirebase REST APIを使用することができます。 AJAXライブラリ(この例ではaxiosを使用します)を使用すると、データベースから簡単にデータを読み取ることができます。

以下は、Firebaseからデータを読み取る方法の例です。

// This first call will return the root of your database 
// By appending the url with '.json', the response will be JSON 
axios('https://**your-database-here**.firebaseio.com/.json') 
.then(response => { 
    // Using .then to access the resolved data from the promise 
    // "response" itself is an object, but our data is assigned to the data property 
    console.log(response.data); 
}); 

// This call will return a single collection, such as the Hotel collection. 
// Be aware that firebase does not return array, but instead returns an object of key - value pairs 
axios('https://**your-database-here**.firebaseio.com/Hotel.json') 
.then(response => { 
    console.log(response.data); 

    var hotel = response.data; // Again, just wait the actual data 
    // Will need to loop over object to get nested data here 
}); 

<script src="https://unpkg.com/axios/dist/axios.min.js"></script> 
関連する問題