1

I'm not a JSON god by any stretch of the imagination, but I'm not understanding why this isn't working, and what I need to do to make it work. I've searched around for a while now and most likely my problem is I don't know the right keywords to search for to solve this. I'm wanting to call a function and, within that function, create a JSON object so I can store it in an IndexedDB "table", like so:

UpdateSettingsValue("initialized", true);

function UpdateSettingsValue(key, value){
    var tx = db.transaction(["settings"], "readwrite");
    var store = tx.objectStore("settings");
    var trans = {
        key:value
    }
    var request = store.add(trans);
}

This is creating an entry just fine, but it gets written as {key: true}.

So my question is how can I make it written as {initialized: true}?

Thanks for your help!

1 Answer 1

2

Just initialize the trans variable by hand instead of using literal syntax:

function UpdateSettingsValue(key, value){
    var tx = db.transaction(["settings"], "readwrite");
    var store = tx.objectStore("settings");
    var trans = {};
    trans[key] = value;
    var request = store.add(trans);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.