简体   繁体   中英

Uncaught TypeError: store.put is not a function at store.onsuccess

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
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

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:

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

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM