[英]Access object properties inside another object
I´m new to Firebase and I want to access the 'name' and 'score' properties. 我是Firebase的新手,我想访问'name'和'score'属性。 How could I do this? 我该怎么办?
Here is the db-structure: 这是db-structure:
I get the whole database like this(following this tutorial ), but I dont knwo how I could access the properties of the objects(for example the name of '-Kk50CJUCI...') inside. 我得到了这样的整个数据库(在本教程之后 ),但是我不知道如何访问内部的对象的属性(例如,'-Kk50CJUCI ...'的名称)。
scores.on('value', getData, errData)
function getData(data) {
console.log(data.val())
}
function errData (err) {
console.log(err)
}
Thanks! 谢谢! :) :)
By adding a child_added
event listener, you will get each child node (-Kk50CJUCI.. etc.) individually. 通过添加child_added
事件侦听器,您将分别获得每个子节点(-Kk50CJUCI ..等)。 You can then directly access the child properties of the data.val()
as below: 然后,您可以直接访问data.val()
的子属性,如下所示:
scores.on('child_added', getData, errData)
function getData(data) {
console.log(data.val().name)
console.log(data.val().score)
}
function errData (err) {
console.log(err)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.