我是 firebase 的新手,我正在尝试分页查询。我喜欢有“下一个”和“上一个”按钮。我的下一个按钮工作正常,我的问题是单击上一个按钮时
参考:https://firebase.google.com/docs/firestore/query-data/query-cursors
目前,我收藏了 10 份文档,我喜欢一次展示 3 份。
加载时我只显示 3 个项目
var first = db.collection("employees").limit(3);
first.get().then(function (documentSnapshots) {
documentSnapshots.docs.forEach(doc => {
//function to display in the HTML
renderEmployee(doc);
});
lastVisible = documentSnapshots.docs[documentSnapshots.docs.length - 1];
});
Run Code Online (Sandbox Code Playgroud)
下一个按钮
$("#js-next").on('click', function () {
$('#employee-table tbody').html('');
var next = db.collection("employees")
.startAfter(lastVisible)
.limit(3);
next.get().then(function (documentSnapshots) {
documentSnapshots.docs.forEach(doc => {
//function to display in the HTML
renderEmployee(doc);
});
lastVisible = documentSnapshots.docs[documentSnapshots.docs.length - 1];
firstVisible = documentSnapshots.docs[documentSnapshots.docs.length - 1];
});
});
Run Code Online (Sandbox Code Playgroud)
上一页(代码问题)
$("#js-previous").on('click', function () …Run Code Online (Sandbox Code Playgroud)