gpt4 book ai didi

javascript - 如何从对象 [Firebase 唯一键] 中检索数据

转载 作者:行者123 更新时间:2023-11-30 14:06:32 25 4
gpt4 key购买 nike

This is the data that i want to retrieve

How can I retrieve the data without knowing the unique ID?

        var query = firebase.database().ref("/Venue").orderByKey();
query.on("value", function (snapshot) {
snapshot.forEach(function (childSnapshot) {
var key = childSnapshot.key;
var childData = childSnapshot.val();
console.log(childData);
});
});

最佳答案

使用 Object.values 来提供帮助。它返回对象属性值的数组

由于 .Data 只有一个属性,您可以轻松获取它的值,它将位于索引 0 处

var query = firebase.database().ref("/Venue").orderByKey();
query.on("value", function (snapshot) {
snapshot.forEach(function (childSnapshot) {
var key = childSnapshot.key;
var childData = childSnapshot.val();
console.log(Object.values(childData.Data)[0]); // change
});
});

关于javascript - 如何从对象 [Firebase 唯一键] 中检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55273713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com