答案 0 :(得分:1)
如果实时参考语法让你失望,你也可以使用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>
答案 1 :(得分:0)
foreach是需要的操作,这个逐个获取数据
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;
});
});
}