我不能更新IndexedDb中的任何数据。当我运行代码时,它说“store.put不是store.onsuccess中的函数”。
- 我尝试从许多浏览器,在所有相同的错误
- 我还尝试了.update而不是.put函数,但它不起作用,并给出相同的错误
const request = window.indexedDB.open("AdminDatabase");
request.onsuccess = (event) => {
const db = event.target.result;
const txn = db.transaction('floors', 'readwrite');
const store = txn.objectStore('floors').get(parseInt(getRoomButtonNumber));
store.onsuccess = function (event) {
var floorDataFromDb = event.target.result;
console.log("RenameFloor: getDbResult: FloorName: " + floorIdFromDb.Name);
floorDataFromDb.Name = person;
console.log("RenameFloor: Json New Name: " + floorDataFromDb.Name);
//In this line caught error
store.put(floorDataFromDb);
store.onsuccess = function (event) {
console.log("floorData Updated: " + event.target.result);
}
};
store.onerror = function (event) {
console.log("GET Error DB: " + event);
};
};
1条答案
按热度按时间qlvxas9a1#
您的问题在这行:
const store = txn.objectStore('floors').get(parseInt(getRoomButtonNumber));
您将store定义为
IDBRequest
。很明显,它没有put方法,您可以将它改为: