关于:无法从“ IDBRequest”读取“ result”属性

时间:2019-08-14 04:14:26

标签: javascript mongodb

我具有提取当前正在登录的用户数据的功能。令人困惑的是,打开请求没有调用任何回调。这确实很烦人,必须解决。

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。看起来像这样。 enter image description here

尽管在结果“ Exception”显示中,我使用了try-catch,但没有发现任何问题。 在这种情况下能否获得结果?

发生此问题时,我从镀铬检查器中观察到了类似 enter image description here

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

欢迎提出任何想法。

0 个答案:

没有答案