From d1ffc57dc3d88079893b2691245d361fc794810d Mon Sep 17 00:00:00 2001 From: Erastus Amunwe Date: Tue, 3 Nov 2020 11:08:24 +0200 Subject: [PATCH] Fixed delete method bug using cursor, fixes #2 --- src/api/idb.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/api/idb.js b/src/api/idb.js index 6f88230..e8bc238 100644 --- a/src/api/idb.js +++ b/src/api/idb.js @@ -42,18 +42,22 @@ export default { }; let store = trans.objectStore(delInfo.name); - console.log("deleting "+ delInfo.keyPath+ " from "+delInfo.name); - let request = store.delete([delInfo.keyPath]); - request.onerror= err => reject(err) - // request.onsuccess = e => console.log(e); - + store.openCursor().onsuccess = e => { + let cursor = e.target.result; + if (cursor) { + if(delInfo.keyPath == cursor.value['abbreviation']){ + let request =cursor.delete() + request.onsuccess = e => console.log(e);} + + cursor.continue(); + } + }; trans.onerror = e => { reject(e) } trans.onabort = e => { reject(e) } - trans.commit(); }); },