最近添加新记录时,我遇到了麻烦。刷新页面时,我会得到最近添加的记录。
在IndexedDB中获取记录的示例代码:
get(id, storeName, callback) {
var trans = this.db.transaction([storeName], "readwrite");
var store = trans.objectStore(storeName);
try{
var process = await store.get(id);
}catch(ex){}
trans.oncomplete = function(event){
callback(process !== undefined ? process.result : null);
delete process;
delete trans;
delete store;
delete go;
};
trans.onerror = function(){
callback(null);
};
}
我收到未定义的错误,因为它似乎未获取新添加的记录。我该如何解决这个问题?