赋值操作是否可以在Javascript中更改对象内容?

时间:2018-05-17 04:20:56

标签: javascript meteor promise indexeddb

我有一段代码从indexeddb检索数据。我已经确认db访问正常:从db检索的数据是正确的。但是通过assign操作对象进行了修改。在快照中,第一个矩形显示从indexedb检索的正确数据。但是

if(uprofile) console.log('urpofile:'+uprofile.shopList.length);

打印另一个故事。

enter image description here

export async function getCurrUser(window) {
return await new Promise((resolve, reject) => {
    window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
    let currUserAcc='',
        openRequest = indexedDB.open('userData',2);
    openRequest.onsuccess =  e => {
        let db = e.target.result;
        let transaction= db.transaction(['users','user_profile'],'readwrite');

        let objStore=  transaction.objectStore('users'), req= objStore.get(0);
        req.onsuccess=function(event){
            let cursor=event.target.result;
            if(cursor) currUserAcc = cursor.account;
            objStore =  transaction.objectStore('user_profile');
            let _req= objStore.get(currUserAcc);
            _req.onsuccess=function(event){
                //the first printout: event retrieved from indexdb is correct
                if(event.target.result) console.log('whole:'+event.target.result.shopList.length);console.log(event)//print a complete event

                let uprofile=event.target.result;
                //the second printout: uprofile content is not same with partial content in event
                if(uprofile) console.log('urpofile:'+uprofile.shopList.length);//from this, I confirm although the uprofile.shopList.length is a number, say 317, that in fact means a array of 317 'undefined'
                if(uprofile) {db.close();resolve(uprofile);}
            };
        };
    }
});
}

我怀疑是否真的是导致此问题的分配操作。欢迎任何想法。非常感谢。

0 个答案:

没有答案