- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要检查某个表在打开后是否已经存在于 IndexedDB 中。但我不知道如何在 'then' 语句中获取 DexieDB 对象。
this.db = new Dexie("DBNAME");
if (!this.db.isOpen()) {
this.db.open().then(function () {
//how to get this.db.table(storeName) here?
}).catch(function (error) {
console.log(error)
});
}
所以 this.db
不存在于 'then' 语句中。如何获取?
最佳答案
特别是在 Dexie 中,你不必像那样调用 isOpen
和 open()
,你可以只调用 .open
等等将像这样工作:
// Declare db instance
var db = new Dexie("MyDatabase");
// Define Database Schema
//...
// Open Database
db.open();
db.trasnaction(...
这是一个经典的 JS 上下文值。 this
在 JavaScript 中的工作方式不同 - here is the canonical reference about it which you should read .
此外 - 关于在 then 链中传递参数你应该引用 this excellent Q&A涵盖了更一般的方法
那里描述的解决方法(有上下文)通常适用并包含更多库特定代码,可以在这里为您提供帮助。
关于javascript - 如何在刚刚通过 Dexie.js 打开 indexedDB 后获取表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28293962/
实现信息技术的自主可控,可以说是金融行业最紧迫、最重要的推进战略了。 人民银行、银保监会等主管部门密集出台文件,指导金融行业核心领域自主可控技术应用。 拿数据库来说,自主可控这事儿业内也
在methods中创建方法showtime,传入要跟当前时间要对比的时间 ?
其实这个没什么技术含量,当然就直接贴代码,不废话了, 但是在其实开发中还是蛮有用的,譬如论坛帖子,围脖等都有相关应用 复制代码代码如下: function tranTim
今天,杭州人的朋友圈都被这场晚会刷屏了 分散在全球的阿里人都回到杭州,为阿里巴巴送上20周岁的生日祝福。 阿里巴巴20周年年会,被称作“有史以来杭州规模最大的年会”,没有
在很多场合为了显示出信息的及时性,一般会将时间显示成“刚刚”,“5分钟前”,“3小时前”等,而不是直接将时间打印出来。比如微博,SNS类应用就最长用到这个功能。而一般存储在数据库中的时间格式为 Un
我是一名优秀的程序员,十分优秀!