dimanche 22 mars 2020

indexeddb issue return value of onsuccess

I am using indexeddb for a project and I am stuck on the following issue:

basically I need to set the value of var varRetorno and make the return value of fOrden

    function fOrden (){

       var varRetorno;

       var active = baseDeDatosContenedores.result;
       var contendor = active.transaction(["indexar"], "readwrite");
       var object2 = contendor.objectStore("indexar");

       var valorId2 = object2.get(2);
       var valorId3 = object2.get(3);
       var valorId1 = object2.get(1);

       valorId1.onsuccess = function (){                  
          if (valorLocal == "falso"){
          varRetorno = valorId1.result.inde;
          var request = object2.put({id:1, status:"enUso", inde: 1});
          }else if (valorLocal2 == "falso"){
          var request = object2.put({id:2, status:"enUso", inde: 2});
          varRetorno = valorId2.result.inde;
          }else if (valorLocal3 == "falso"){
          var request = object2.put({id:3, status:"enUso", inde: 3});
          varRetorno = valorId3.result.inde;
          }else {console.log("Todo funciona");}
         }
return varRetorno;
}

why my if statment do not set the value of my var? is it about the "onsuccess" scope?

thank you in advance !

kind regards.

Aucun commentaire:

Enregistrer un commentaire