根據
我錯過了什么嗎?
謝謝!
uj5u.com熱心網友回復:
你playersByPoints這里是一個Query物件,當記錄它回傳鏈接資料庫參考的字串。
您需要使用get(q)或來實際呼叫查詢,onValue(q)以獲取您要查找的資料。
// one-off
const playersByPointsQuery = query(
ref(db, 'usersPoints'),
orderByChild('points'),
);
const playersByPointsQuerySnapshot = await get(playersByPointsQuery);
const playersByPoints = [];
playersByPointsQuerySnapshot.forEach(childSnapshot => {
playersByPoints.push({
...childSnapshot.val(),
_key: childSnapshot.key
});
});
// todo: do something with playersByPoints
或者
// realtime listener
const playersByPointsQuery = query(
ref(db, 'usersPoints'),
orderByChild('points'),
);
const unsubscribe = onValue(
playersByPointsQuery,
{
next: (playersByPointsQuerySnapshot) => {
// new data available
const playersByPoints = [];
playersByPointsQuerySnapshot.forEach(childSnapshot => {
playersByPoints.push({
...childSnapshot.val(),
_key: childSnapshot.key
});
});
// todo: do something with playersByPoints
},
error: (err) => {
// error
// todo: handle
}
}
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/497482.html
