javascript - JavaScript:如何从 IndexedDB 中检索最新记录?
问题描述
我正在编写一个用户脚本,其主要目标是跟踪观看的剧集。在 IndexedDB 我有一个 objectStore({keyPath: 'episode', autoIncrement: true})watchedList
包含 objects {episode: [the episodes id], currentTime: [episode watched till here]}
。我现在的问题是:如何从watchedList
.
我将idb Promise Libary用于 IndexedDB API。这就是我的方法。
db.get('watchedList', IDBKeyRange.lowerBound(1)).then(data => {
console.log(data);
})
db.getAll('watchedList').then(data => {
console.log(data);
})
db.getAll('watchedList', null, 1).then(data => {
console.log(data);
})
1:将记录第一条记录(最低id)
2:将首先记录具有最低 id 的数组
3:将记录一个包含第一条记录的数组
如何对结果进行排序?
通过以下方法实现我的目标是个好主意吗?
db.getAll('watchedList').then(data => {
console.log(data.pop());
})
解决方案
尝试使用openCursor
并将方向参数指定为prev
推荐阅读
- django - Django Environ:管理电子邮件密码时 SMTPServerDisconnected
- java - 为终端程序编译外部库?
- bash - Bash - 移动包含特定字符串的文件
- blazor - 避免在整个布局的 Blazor 解决方案中页面转换时出现“多步刷新”
- java - 如何在不获取 java.lang.ArrayIndexOutOfBoundsException 的情况下将此伪代码转换为 Java
- c - 在 C 中调用 fwrite 函数后如何检查成功写入?
- sql-server - SQL:按位运算
- r - 如果存在于 =.> 3 个数据框中(共 5 个)中,如何删除常见元素
- rust - 无法在用户定义类型的“Vec”中添加分配
- r - r 相关性的 Corr 图不适用于“距离法”。如何从头开始创建 corr 图?