•––•••
–
localStoragewindow.localStorage.setItem(“name”, “Ivano”);var name = window.localStorage.getItem(“name”);
.key(0).getItem(“key”).setItem(“key”, “value”).removeItem(“key”).clear()

// simple class declarationfunction Person(name, surname) {this.name = name;this.surname = surname;}// object creationvar ...
if (window.localStorage.getItem(“user”)) {// there is an object in user} else {// the user key does not have any value}
var users = [...]; // array of Person objectswindow.localStorage.setItem(“users”,JSON.stringify(users));var allUsers =JSON...
var usersNumber =JSON.parse(window.localStorage.getItem(“users“)).length;

tx.executeSql("SELECT * FROM User“, [],function(tx, result) {// callback code});
var db =openDatabase(„Test, „1.0, „Test DB, 100000);
openDatabase(name, version, displayname, size);
db.changeVersion("1.0", "1.1");
db.transaction(queries, error, success);
function populateDB(tx) {tx.executeSql(DROP TABLE IF EXISTS USER);tx.executeSql(CREATE TABLE IF NOT EXISTS USER (idunique,...
rows
...tx.executeSql(INSERT INTO USER(id, name,surname) VALUES (5,?, ?)„, [“Ivano“, “Malavolta“], success, error);}function su...
lengthitem(index)
...tx.executeSql(„SELECT * FROM USER„, [], success, error);}function success(tx, results) {var size = results.rows.length;...
••
...tx.executeSql(„SELECT * FROM USER„,[], success, error);}function error(err) {console.log(err.code);}


–––––
requestFileSystem(type, size, successCb, [errorCb])

window.requestFileSystem(LocalFileSystem.PERSISTENT,0,onSuccess,onError);function onSuccess(fileSystem) {console.log(fileS...
window.resolveLocalFileSystemURI("file:///userImg.png", onSuccess, onError);function onSuccess(fileEntry) {console.log(fil...
The real objectsDescriptorWriting & Reading objects

entry.file(win, fail);function win(file) {var reader = new FileReader();reader.onloadend = function(evt) {console.log(evt....
append
entry.createWriter(win, fail);function win(writer) {writer.onwrite = function(evt) {console.log(“ok");};writer.write(“Ivan...
var directoryReader = dirEntry.createReader();directoryReader.readEntries(success, fail);function success(entries) {var i;...
window.requestFileSystem(window.PERSISTENT, 0, initFS, error);function initFS(fs) {fs.root.getFile(„log.txt, {}, win, erro...
• •• ••
• • • • •
• • • • • •
• •••

PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
Upcoming SlideShare
Loading in...5
×

PhoneGap: Local Storage

6,615

Published on

PhoneGap: Local Storage

This presentation has been developed in the context of the Mobile Applications Development course, DISIM, University of L'Aquila (Italy), Spring 2013.

http://www.ivanomalavolta.com

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,615
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
186
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

PhoneGap: Local Storage

  1. 1. •––•••
  2. 2.
  3. 3. localStoragewindow.localStorage.setItem(“name”, “Ivano”);var name = window.localStorage.getItem(“name”);
  4. 4. .key(0).getItem(“key”).setItem(“key”, “value”).removeItem(“key”).clear()
  5. 5. 
  6. 6. // simple class declarationfunction Person(name, surname) {this.name = name;this.surname = surname;}// object creationvar user = new Person(„Ivano‟, „Malavolta‟);// object serializationwindow.localStorage.setItem(“user”, JSON.stringify(user));// object retrievalvar current =JSON.parse(window.localStorage.getItem(“user”));
  7. 7. if (window.localStorage.getItem(“user”)) {// there is an object in user} else {// the user key does not have any value}
  8. 8. var users = [...]; // array of Person objectswindow.localStorage.setItem(“users”,JSON.stringify(users));var allUsers =JSON.parse(window.localStorage.getItem(“users”));var ivanos = [];for(var i=0; i<allUsers.length; i++) {if(allUsers[i].name == „Ivano‟)ivanos.push(allUsers[i]);}
  9. 9. var usersNumber =JSON.parse(window.localStorage.getItem(“users“)).length;
  10. 10.
  11. 11. tx.executeSql("SELECT * FROM User“, [],function(tx, result) {// callback code});
  12. 12. var db =openDatabase(„Test, „1.0, „Test DB, 100000);
  13. 13. openDatabase(name, version, displayname, size);
  14. 14. db.changeVersion("1.0", "1.1");
  15. 15. db.transaction(queries, error, success);
  16. 16. function populateDB(tx) {tx.executeSql(DROP TABLE IF EXISTS USER);tx.executeSql(CREATE TABLE IF NOT EXISTS USER (idunique, name, surname));tx.executeSql(INSERT INTO USER(id, name, surname)VALUES (1, ?, ?)„, [“Ivano“, “Malavolta“],success, error);}
  17. 17. rows
  18. 18. ...tx.executeSql(INSERT INTO USER(id, name,surname) VALUES (5,?, ?)„, [“Ivano“, “Malavolta“], success, error);}function success(tx, results) {var affected = results.rowsAffected(); // 1}function error(err) {// code for managing the error}
  19. 19. lengthitem(index)
  20. 20. ...tx.executeSql(„SELECT * FROM USER„, [], success, error);}function success(tx, results) {var size = results.rows.length;for (var i=0; i<size; i++){console.log(results.rows.item(i).name);}}
  21. 21. ••
  22. 22. ...tx.executeSql(„SELECT * FROM USER„,[], success, error);}function error(err) {console.log(err.code);}
  23. 23.
  24. 24.
  25. 25. –––––
  26. 26. requestFileSystem(type, size, successCb, [errorCb])
  27. 27.
  28. 28. window.requestFileSystem(LocalFileSystem.PERSISTENT,0,onSuccess,onError);function onSuccess(fileSystem) {console.log(fileSystem.name);}
  29. 29. window.resolveLocalFileSystemURI("file:///userImg.png", onSuccess, onError);function onSuccess(fileEntry) {console.log(fileEntry.name);}
  30. 30. The real objectsDescriptorWriting & Reading objects
  31. 31.
  32. 32. entry.file(win, fail);function win(file) {var reader = new FileReader();reader.onloadend = function(evt) {console.log(evt.target.result);};reader.readAsText(file);// reader.abort();};function fail(evt) {console.log(error.code);};
  33. 33. append
  34. 34. entry.createWriter(win, fail);function win(writer) {writer.onwrite = function(evt) {console.log(“ok");};writer.write(“Ivano Malavolta");};function fail(evt) {// error management};
  35. 35. var directoryReader = dirEntry.createReader();directoryReader.readEntries(success, fail);function success(entries) {var i;for (i=0; i<entries.length; i++) {console.log(entries[i].name);}}function fail(error) {console.log(error.code);}
  36. 36. window.requestFileSystem(window.PERSISTENT, 0, initFS, error);function initFS(fs) {fs.root.getFile(„log.txt, {}, win, error);}function win(fileEntry) {fileEntry.file(read, error);}function read(file) {var reader = new FileReader();reader.onloadend = function(e) {console.log(this.result);};reader.readAsText(file);}function error(err) { console.log(err);}
  37. 37. • •• ••
  38. 38. • • • • •
  39. 39. • • • • • •
  40. 40. • •••
  41. 41. 
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×