axemclion / jquery-indexeddb

An IndexedDB Plugin for Jquery.
Other
195 stars 71 forks source link

help inserting data #16

Closed scott-davidjones closed 11 years ago

scott-davidjones commented 11 years ago

HI

Im looking for a bit of help.

I have a javascript login page which redirects a user on sucessful login.

I want to be able to add a load of data to my indexeddb for use around the site instead of firing of ajax requests all the time; however my login script redirects the user before all of the data is stored in the db. (there can be quite a lot of it.)

I am looping through a response object like so:

var lookup = $.indexedDB("atlas").objectStore("Lookup");
    lookup.clear();
    $.each(obj, function(){
        lookup.add(this);
    });

is there a way i can detect when the entirety of the above has completed?

axemclion commented 11 years ago

You could start using a transaction and wait for oncomplete of the transaction, something like


var lookup = $.indexedDB('atlas').transaction([atlas]).done(function(){
 // transaction has completed, you are good to go. 
})progress(function(){
 // transaction is in progress here, do the adding to DB
})
scott-davidjones commented 11 years ago

Thanks for the quick reply. I have instigated that but now i dont seem to be able to get any data to insert..

Im not sure if i have fully understood the way in which to insert multiple data. I am using the Resource Viewer in chrome to check that data is there.. my code is:

var lookup = $.indexedDB('atlas').transaction(["Lookup", "BinRanges", "Company", "Region", "Agents", "Features", "Pickups"]).done(function(){
        // transaction has completed, you are good to go.
        console.log("Transaction Complete");
        lBool = true;
       }).progress(function(){
            // transaction is in progress here, do the adding to DB
            var lookupOS = $.indexedDB("atlas").objectStore("Lookup");
            lookupOS.clear();
            console.log(obj.Lookup);
            $.each(obj.Lookup, function(){
                lookupOS.add(this);
            });
       })