我正在使用 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",
]
這與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)
}
uj5u.com熱心網友回復:
您從 Firebase 回傳的內容稱為DataSnapshot,并包含您讀取的位置的 JSON 以及更多元資料。
如果您只想獲取快照的 JSON 值,請使用snapshot.val()Expo 檔案中的Storage Data and Receiving Updates。
就像是:
const existingData = await get(query(readReference))
const dataKeys = Object.keys(existingData.val())
console.log(dataKeys)
console.log(existingData.val())
console.log(typeof existingData.val())
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/399765.html
標籤:javascript 反应原生 火力实时数据库 世博会
上一篇:在Moongose上查找一位用戶
