【发布时间】:2021-12-31 20:50:35
【问题描述】:
我正在使用 Expo 构建一个 React Native 应用程序并集成 Firebase(实时数据库),我知道这有一些限制 (https://docs.expo.dev/guides/using-firebase/)。我正在尝试使用await get(query(... 获取数据的快照并已成功完成,但我无法弄清楚我正在使用什么。当我console.log 它时,我得到了这个:
Object {
"key1": value1,
"key2": value2,
}
我试图使用 Object.keys() 返回一个键数组,但它返回了这个:
Array [
"_node",
"ref",
"_index",
]
这与我在 Internet 上看到的 Object.keys() 的示例不符,这让我认为这不是我认为的 JSON 对象。我试过用其他一些东西到处乱摸,但无法弄清楚。问题是,当我在对象上使用 typeof 时,它只是返回“对象”,这对我来说有点太模糊了,无法带到谷歌机器上。
以下是我的代码的表示。感谢您的帮助。
import { initializeApp } from 'firebase/app';
import { get, getDatabase, query, ref } from 'firebase/database';
const firebaseConfig = {
databaseURL: '<myURL>',
projectId: '<myID>',
};
const app = initializeApp(firebaseConfig);
export default async function myFunction() {
const db = getDatabase(app);
const readReference = ref(db, '/<I am only reading a piece of the data>')
const existingData = await get(query(readReference))
const dataKeys = Object.keys(existingData)
console.log(dataKeys)
console.log(existingData)
console.log(typeof existingData)
}
【问题讨论】:
标签: javascript react-native firebase-realtime-database expo