Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught DOMException: Failed to execute 'put' on 'IDBObjectStore': Evaluating the object store's key path did not yield a value

Tags:

indexeddb

I have an indexeddb and when I open my site for the first time in my chrome and try invoke init.savedb(); I receive an error telling Uncaught DOMException: Failed to execute 'put' on 'IDBObjectStore': Evaluating the object store's key path did not yield a value.

Then I reload the page and everything works fine.

Does someone have any idea what did I do wrong?

here is the code:

var model = {
everything: {},
db: {},
goals: [],
tags: [],



init: function () {
    var openReq = window.indexedDB.open("micromanagerv999");
    openReq.onupgradeneeded = function (event) {

        model.db = event.target.result;
        var objectStore = model.db.createObjectStore("Everything", { keyPath: "id" });

        objectStore.createIndex("id", "id", { unique: true });


    };
    openReq.onsuccess = function (event) {
        model.db = event.target.result;
        model.db.transaction("Everything", "readonly").objectStore("Everything").count().onsuccess = function (event) {
            if (event.target.result === 0) {


                var basictemplate = {
                    id: "idee",
                    goals: [],

                };
                var addReq = model.db.transaction("Everything", "readwrite").objectStore("Everything").add(basictemplate);

            } else {
                model.db.transaction("Everything", "readonly").objectStore("Everything").get("idee").onsuccess = function (e) {

                    model.everything = e.target.result;
                    model.goals = model.everything.goals;
                    if (model.everything.tags == undefined) {
                        model.everything.tags = [];
                        model.tags = model.everything.tags;
                    } else {
                        model.tags = model.everything.tags;
                    }

                   microGoals.renderArray();
                };

            }

        };
        openReq.onerror = function (event) {
            console.log("Operation failed");
        };

    }
},
savedb: function () {



    var update = model.db.transaction("Everything", "readwrite").objectStore("Everything").put(model.everything);

    update.onerror = function (event) {
        console.log(event);
    }
}



};  // End of MODEL
like image 814
Peter Avatar asked Mar 07 '23 19:03

Peter


1 Answers

just answersing so you can mark as answered. see my comment:

in savedb, try logging the value of model.everything before calling put, and check if the object has a property named id

like image 100
Josh Avatar answered Apr 07 '23 20:04

Josh