[英]Retrieving data with firebase for Web
我正在尝试从firebase数据库中检索数据:
firebase.database().ref("/appointments").orderByChild("doctor").equalTo(doctorId).on("value", function(snapshot) {
var appointmentsData = snapshot.val();
for(var appointment in appointmentsData) {
if (!appointmentsData.hasOwnProperty(appointment)) continue;
var obj = appointmentsData.appointment;
}
});
如果我在console.log约会或console.log约会数据,我得到正确的值,但如果我console.log约会Data.appointment,我得到undefined。
知道如何从firebase返回的对象中检索属性和值吗?
您想使用Firebase
内置的forEach
功能。 它允许您遍历快照并轻松获取该对象内每个属性的键和值。 它可能是另一个对象或平面值。
firebase.database().ref("/appointments").orderByChild("doctor").equalTo(doctorId).on("value", function(snapshot) {
snapshot.forEach(function(childSnapshot) {
// key
var key = childSnapshot.key;
// value, could be object
var childData = childSnapshot.val();
// Do what you want with these key/values here
...
});
});
参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.