我具有提取当前正在登录的用户数据的功能。令人困惑的是,打开请求没有调用任何回调。这确实很烦人,必须解决。
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.*/}
});
}
尽管在结果“ Exception”显示中,我使用了try-catch,但没有发现任何问题。 在这种情况下能否获得结果?
没有版本(加载似乎卡住了)。但是数据库仍然存在。
欢迎提出任何想法。