我正在使用 Firebase 進(jìn)行分頁,到目前為止,我有一個按鈕可以前進(jìn),另一個按鈕可以返回,它們工作正常,但是我無法檢測是在第一頁還是最后一頁,所以我可以禁用分頁按鈕,所以想知道它是如何工作的,我應(yīng)該改變分頁數(shù)據(jù)的方式嗎?export const getNextItems = (last_Visible) => { return async (dispatch, getState, { getFirebase }) => { const firestore = getFirebase().firestore(); // const items = []; const dbRef = firestore .collection('items') .orderBy('createdAt', 'desc') .startAfter(last_Visible) .limit(2); const usersRef = firestore.collection('users'); let temps = []; const { data: items, firstVisible, lastVisible } = await dbRef.get().then(getAllDocs); for (const item of items) { const { data: user } = await usersRef.doc(item.owner).get().then(getDoc); temps.push({ ...item, owner: user }); } return { docs: temps, lastVisible, firstVisible }; };};export const getPrevItems = (first_Visible) => { return async (dispatch, getState, { getFirebase }) => { const firestore = getFirebase().firestore(); // const items = []; const dbRef = firestore .collection('items') .orderBy('createdAt', 'desc') .endBefore(first_Visible) .limitToLast(2); const usersRef = firestore.collection('users'); let temps = []; const { data: items, lastVisible, firstVisible } = await dbRef.get().then(getAllDocs); for (const item of items) { const { data: user } = await usersRef.doc(item.owner).get().then(getDoc); temps.push({ ...item, owner: user }); } return { docs: temps, lastVisible, firstVisible }; };};
在firebase中分頁時如何檢測第一頁或最后一頁中的am
胡說叔叔
2022-11-03 14:47:18