Advertisement
Guest User

FCM#70 - CRUD 5

a guest
Feb 10th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. // display the data from local storage to screen
  2. function displayData() {
  3. // empty out our current list
  4. ge('ubuntuVersionsDisplayList').innerHTML = "";
  5.  
  6. // check if localstorage has anything in it
  7. if (localStorage.length === 0) {
  8. alert('There is no data in Local Storage');
  9. }
  10. else { // there is local storage info
  11.  
  12. // loop through each item in local storage
  13. for (var i=0, j=localStorage.length; i<j; i++) {
  14. // Put the information from the localStorage row into some variables
  15. var key = localStorage.key(i),
  16. value = localStorage.getItem(key),
  17. obj = JSON.parse(value);
  18.  
  19. // let's check if the key for the entry starts with our ubuvers id.
  20. // substring lets you grab portions of the string. 0 is the first
  21. // character, and 7 means it goes up to character 7. This will read
  22. // charachters 1-7 (u b u V e r s). Note: It doesn't read the last
  23. // character.
  24. if (key.substring(0,7) == "ubuVers") {
  25. // let's check to make sure we are getting the right keys out
  26. console.log(key);
  27. console.log(obj);
  28.  
  29. // now that we have our key right. let's display the data already added
  30. var list = ge('ubuntuVersionsDisplayList'),
  31. listItem = document.createElement('li'),
  32. ubuVersNumValue = obj.version,
  33. ubuVersNameValue = obj.release,
  34. listText = ubuVersNumValue + ": " + ubuVersNameValue + ' ',
  35. itemDeleteButton = document.createElement('button'),
  36. itemDeleteButtonText = "Remove Item";
  37. itemEditButton = document.createElement('button'),
  38. itemEditButtonText = "Edit Item";
  39.  
  40. itemDeleteButton.setAttribute('id',key),
  41. itemDeleteButton.onclick = function() {deleteItem(this.id)};
  42. itemEditButton.setAttribute('id',key),
  43. itemEditButton.onclick = function() {editItem(this.id)};
  44.  
  45. listItem.innerHTML = listText;
  46. itemEditButton.innerHTML = itemEditButtonText;
  47. itemDeleteButton.innerHTML = itemDeleteButtonText;
  48.  
  49. listItem.appendChild(itemEditButton);
  50. listItem.appendChild(itemDeleteButton);
  51.  
  52. list.appendChild(listItem);
  53. }
  54. }
  55. }
  56. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement