首页 > 解决方案 > 关于:无法从“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.*/}
    });

}

所以,我打印出了 openrequest。它看起来像这样。 在此处输入图像描述

尽管在结果“异常”显示中,我使用了 try-catch 并没有被捕获。在这种情况下有可能得到结果吗?

发生此问题时,我从 chrome 检查器观察并看到类似 在此处输入图像描述

没有版本(加载似乎卡住了)。但是数据库仍然存在。

欢迎任何想法。

标签: javascriptmongodb

解决方案


推荐阅读