Skip to content

Instantly share code, notes, and snippets.

@glynrob
Created January 27, 2013 12:24
Show Gist options
  • Save glynrob/4648138 to your computer and use it in GitHub Desktop.
Save glynrob/4648138 to your computer and use it in GitHub Desktop.
Save data with websql
function saveLocally(dataToSave){
db.transaction(function (tx) { // this is nasty but truncate is not available on sqllite
tx.executeSql('DROP TABLE data ');
tx.executeSql('CREATE TABLE IF NOT EXISTS data (id unique, text)');
});
$.each(dataToSave, function(key, val) { // loop through each item in savedData
if (val){
db.transaction(function (tx) {
tx.executeSql('INSERT INTO data (id, text) VALUES (?, ?)', [val['label'], val['value']]);
});
}
});
showListItems(); // refresh the list display
showLocalData(); // update localdata display
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment