javascript - 关于:无法从“IDBRequest”读取“结果”属性
问题描述
我有一个功能来获取当前登录用户的数据。令人困惑的是,打开请求没有调用任何回调。这真的很烦人,必须解决。
export async function getCurrUser(window) {
return await new Promise((resolve, reject) => {
window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
let currUserAcc='curuser',//the currently login-ing user
openRequest = indexedDB.open('userData',2);/*this line didnt call any callbacks bellow. why?*/
openRequest.onsuccess = e => {
let db = e.target.result;
try{
//access users and shops tables in indexeddb
let transaction= db.transaction(['users','shops'],'readwrite');
let objStore= transaction.objectStore('users'), req= objStore.get('curuser');
//callbacks handling req
...
} catch (e) {db.close();}
}
openRequest.onupgradeneeded = e => {
//create the indexeddb
let db = e.target.result;
if(db) {
//create users and shops tables
db.close();
}
}
openRequest.onerror=e=> {/*this does printings. but it didnt come here.*/}
});
}
尽管在结果“异常”显示中,我使用了 try-catch 并没有被捕获。在这种情况下有可能得到结果吗?
没有版本(加载似乎卡住了)。但是数据库仍然存在。
欢迎任何想法。
解决方案
推荐阅读
- json - 检查响应是否有错误
- node.js - 如何为 React Survey Web 应用程序生成自定义 URL
- node.js - Phantom JS + Docker:从 HTML 转换时不尊重 html 字体系列
- api - 如何在 Xamrin.iOS 的标签中调用 api 并显示其中的信息?
- entity-framework - 实体框架核心种子来自文件的大数据
- django - 从视图重复向 django 模板发送数据
- google-apps-script - google-apps-script 谷歌日历空事件
- php - 在php中读取json,处理文件并将json写回磁盘
- firefox - Mozilla Firefox > 开发者工具 > 控制台 > XHR 响应面板(高度)
- c# - 通用类型的 Json 转换器