javascript - localForage 迭代不适用于 JS 文件
问题描述
数据库中有 6 个键,我通过在浏览器控制台中检查它来确认它。
下面的代码只循环了 3 次,条件变为 false 后,它就停止了。
localforage.iterate(function (value, key, iterationNumber) {
console.log(key);
if (key != lastReminderIdKey) {
//console.log(value);
}
}).then(function (value) {
console.log('Iteration has completed');
}).catch(function (err) {
console.log(err);
});
该代码在 HTML 文件中时运行良好。然后我将它移到一个 JS 文件中,迭代/循环现在只部分工作。当我将它移回 HTML 文件时,它工作正常。
DB 中的键是1, 2, lastReminderKey, 3, 4, 5
. 在控制台日志中,当从 JS 文件运行时,它会打印:
1
2
lastReminderKey
Iteration has completed
这种行为的原因可能是什么?
解决方案
您可能在 2 个地方使用不同的 localforage 配置。尝试验证两个 localforage 实例是否具有完全相同的name
、storeName
和driver
.
您可以在选项对象上检查这些属性。
const options = localforage.config();
推荐阅读
- xamarin.forms - 确保 SkiaSharp 字体和 Xamarin Forms 默认字体匹配
- javascript - 将跳动效果平滑地设置为正常比例
- git - 为 git lfs 使用 azure blob 存储
- ios - Xcode 在情节提要中找不到编辑器
- typescript - 在不启动 HTTP 服务器的情况下运行 NestJS 调度程序
- python - Keras model.predict 给出不一致的值
- reactjs - 显示带有电子邮件 ID 的警报
- mesibo - 使用谷歌云的 Mesibo 本地集成问题
- kotlin - 如何每次都在 Kotlin 中制作后台服务
- c++ - 从模板参数中提取 simd 向量长度以用于本地类型