IndexedDB 未捕获的类型错误:store.put不是store.onsuccess中函数

thigvfpy  于 2022-12-09  发布在  IndexedDB
关注(0)|答案(1)|浏览(146)

我不能更新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);

      };
    };

IndexedDb Browser View

qlvxas9a

qlvxas9a1#

您的问题在这行:const store = txn.objectStore('floors').get(parseInt(getRoomButtonNumber));
您将store定义为IDBRequest
很明显,它没有put方法,您可以将它改为:

const store = txn.objectStore('floors');

const res = store.get(parseInt(getRoomButtonNumber));

res.onsuccess = evt => {
  ...
  store.put(data, key);
  ...
}

res.onerror = evt => {
  ...
}

相关问题