I know this is a noobie question, but I just can't figure out why I'm gettgin undefined when I try to console log the property of an object from my database when I'm using the following forEach function.
(我知道这是一个noobie问题,但是当我使用以下forEach函数尝试从数据库中控制台记录对象的属性时,我只是想不出为什么我未定义gettgin的原因。)
readLocations = () => {
console.log("readlocations called")
let locations =
firebase
.database()
.ref("/locations/");
locations.on('value', (snapshot) => {
snapshot.forEach((thing) => {
console.log("thingy object", thing)
console.log("thingy latitude", thing.latitude)
})
});
}
The first console.log logs the following
(第一个console.log记录以下内容)
thingy Object {
"created_at": 1574980834124,
"latitude": 52.4673777,
"longitude": 13.4327486,
}
thingy Object {
"created_at": 1575026634915,
"latitude": 52.5169399,
"longitude": 13.4175105,
}
thingy Object {
"created_at": 1575043262077,
"latitude": 52.5177105,
"longitude": 13.4153796,
}
thingy Object {
"created_at": 1575115938922,
"latitude": 52.5097333,
"longitude": 13.2829992,
}
However, the second log returns undefined
(但是,第二个日志返回未定义)
thingy latitude undefined
thingy latitude undefined
thingy latitude undefined
thingy latitude undefined
thingy latitude undefined
What am I missing here?
(我在这里想念什么?)
ask by Yahir Casas translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…