Ver Mensaje Individual
  #5 (permalink)  
Antiguo 27/05/2015, 07:33
Avatar de lauser
lauser
Moderator Unix/Linux
 
Fecha de Ingreso: julio-2013
Ubicación: Odessa (Ukrania)
Mensajes: 3.278
Antigüedad: 10 años, 9 meses
Puntos: 401
Respuesta: Carrito de la Compra

Editado.... ahora se ve bien. Se paciente y se te ayudara.
Código Javascript:
Ver original
  1. window.indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;
  2.  
  3. if ('webkitIndexedDB' in window) {
  4. window.IDBTransaction = window.webkitIDBTransaction;
  5. window.IDBKeyRange = window.webkitIDBKeyRange;
  6. }
  7.  
  8.  
  9. var GDev={}
  10. GDev.IDB={}
  11. GDev.IDB.db=null
  12.  
  13.  
  14. GDev.IDB.open=function(){
  15. var AccesoAPI=indexedDB.open("PruebaGDev", 1);
  16.  
  17. AccesoAPI.onsuccess=function(e){
  18. GDev.IDB.db=e.target.result
  19.  
  20. GDev.IDB.versiones()
  21. }
  22.  
  23. AccesoAPI.onfailure=GDev.IDB.error
  24. }
  25.  
  26.  
  27. GDev.IDB.versiones=function(){
  28. var base_datos=GDev.IDB.db
  29. var Version=1
  30. if(Version!=base_datos.version){
  31.  
  32. var rVersion=base_datos.setVersion(Version)
  33. rVersion.onfailure=GDev.IDB.error
  34. rVersion.onsuccess=function(e){
  35. if(base_datos.objectStoreNames.contains("Productos ")) {
  36. base_datos.deleteObjectStore("Productos")
  37. }
  38. base_datos.createObjectStore("Productos",{keyPath: "ID"})
  39.  
  40. e.target.transaction.oncomplete=GDev.IDB.anadirPro ductos
  41.  
  42. }
  43. }else{
  44. GDev.IDB.anadirProductos()
  45. }
  46. }
  47.  
  48.  
  49. GDev.IDB.anadirProductos=function(){
  50. var base_datos=GDev.IDB.db
  51. var trans=base_datos.transaction("Productos",'readwrit e')
  52.  
  53. var Almacen=trans.objectStore("Productos")
  54. var AJAX=[
  55. {id:21992,name:"Pantalon Adidas "},
  56. {id:21261,name:"Pantaon largo Adidas"},
  57. {id:21390,name:"Camiseta deportiva"},
  58. {id:22082,name:"Camiseta adidas"},
  59. {id:21992,name:"Camiseta Nike Mujer"},
  60. {id:21261,name:"Camiseta Estandar"},
  61. {id:21390,name:"Balon futbol 11 "},
  62. {id:22082,name:"Raqueta Paddel"},
  63. {id:22082,name:"Botas futbol 11"},
  64. {id:22082,name:"Camiseta Rayo Vallecano"},
  65. ]
  66.  
  67. GDev.IDB.nProducto=AJAX.length
  68. GDev.IDB.contProducto=0
  69. for(var i=0;i<AJAX.length;i++){
  70. var RespNuevo=Almacen.put({
  71. "ID":AJAX[i].id,
  72. name:AJAX[i].name
  73. })
  74. RespNuevo.onfailure=GDev.IDB.error
  75. RespNuevo.onsuccess=GDev.IDB.mostrarProductos
  76. }
  77. }
  78.  
  79.  
  80. GDev.IDB.mostrarProductos=function(){
  81. GDev.IDB.contProducto++
  82. if(GDev.IDB.contProducto>=GDev.IDB.nProducto){
  83.  
  84.  
  85. var base_datos=GDev.IDB.db
  86. var trans=base_datos.transaction("Productos",'readwrit e')
  87. var Almacen=trans.objectStore("Productos")
  88.  
  89.  
  90. var rangoSel = IDBKeyRange.lowerBound(0)
  91. var Busqueda = Almacen.openCursor(rangoSel)
  92.  
  93. Busqueda.onfailure=GDev.IDB.error
  94.  
  95. document.body.innerHTML=''
  96. Busqueda.onsuccess = function(e) {
  97. var resultado = e.target.result
  98. if(!!resultado == false) return false
  99.  
  100. GDev.IDB.escribir(resultado.value)
  101. resultado.continue()
  102. }
  103. }
  104. }
  105.  
  106.  
  107. GDev.IDB.escribir=function(elemento){
  108. document.body.innerHTML+=
  109. '<b>ID</b>: '+elemento.ID+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
  110. '<b>Producto</b>: '+elemento.name+'<br>'
  111. }
  112.  
  113.  
  114. GDev.IDB.error=function(){alert("Ha ocurrido un error")}
  115. GDev.IDB.open()
__________________
Los usuarios que te responden, lo hacen altruistamente y sin ánimo de lucro con el único fin de ayudarte. Se paciente y agradecido.
-SOLOLINUX-