I can’t update any data in IndexedDb. When I run the code it says “store.put is not a function at store.onsuccess”.
- I tried from many browsers, same error in all
- I also tried .update instead of .put function but it didn’t work and gave the same error
JavaScript
x
35
35
1
const request = window.indexedDB.open("AdminDatabase");
2
3
request.onsuccess = (event) => {
4
const db = event.target.result;
5
6
const txn = db.transaction('floors', 'readwrite');
7
8
const store = txn.objectStore('floors').get(parseInt(getRoomButtonNumber));
9
10
store.onsuccess = function (event) {
11
var floorDataFromDb = event.target.result;
12
console.log("RenameFloor: getDbResult: FloorName: " + floorIdFromDb.Name);
13
14
floorDataFromDb.Name = person;
15
16
console.log("RenameFloor: Json New Name: " + floorDataFromDb.Name);
17
18
//In this line caught error
19
20
store.put(floorDataFromDb);
21
22
store.onsuccess = function (event) {
23
console.log("floorData Updated: " + event.target.result);
24
25
}
26
27
28
};
29
30
store.onerror = function (event) {
31
console.log("GET Error DB: " + event);
32
33
};
34
};
35
Advertisement
Answer
You issue is on this line:
const store = txn.objectStore('floors').get(parseInt(getRoomButtonNumber));
You define store as an IDBRequest
.
Obviously, this does not have a put method. You would instead change it to this:
JavaScript
1
14
14
1
const store = txn.objectStore('floors');
2
3
const res = store.get(parseInt(getRoomButtonNumber));
4
5
res.onsuccess = evt => {
6
7
store.put(data, key);
8
9
}
10
11
res.onerror = evt => {
12
13
}
14