Pass parameter to a callback function

Asked

Viewed 305 times

1

I need to pass a parameter to a callback function.

Actually the idea is this:

I search in the database members of a team, in case the table is PESSOA_EQUIPE And in this database there’s her code data and the identifier, if she’s a normal person, if she’s a leader, a helper. With this information I go in the person table and search which are the people, to get the name and some other data.

The code is as follows::

var transaction = db.transaction(["tbl_PESSOAS"]);
var objectStore = transaction.objectStore("tbl_PESSOAS");
for(var i = 0; i < arrayCursor.length; i++){
    var auxObj = new Object();
    auxObj = arrayCursor[i].FLG_IDENT_PESSO; //PRECISO QUE ESTE OBJETO SEJA VISUALIZADO DENTRO DO PONTO 01

    var request = objectStore.get(arrayCursor[i].COD_IDENT_PESSO);
    request.onsuccess = function (event) { //MINHA FUNÇÃO DE CALLBACK
        var arrayVelhoAux = new Object();
        pessoa = event.target.result;

        arrayVelhoAux.FLG_IDENT_PESSO = auxObj; //PONTO 01, É AQUI QUE PRECISA SER VISTO
        arrayVelhoAux.COD_IDENT_PESSO = pessoa.COD_IDENT_PESSO;
        arrayVelhoAux.TXT_NOMEX_PESSO = pessoa.TXT_NOMEX_PESSO;
        arrayVelhoAux.FLG_STATU_PESSO = pessoa.FLG_STATU_PESSO;

        arrayVelho.push(arrayVelhoAux);

        console.log(arrayVelho);
    }
}
transaction.oncomplete = function (event) {}
  • before the push to arrayVelho, the data of the auxObj appears inside the console.log(arrayVelhoAux); ?

  • Yeah. He shows up

  • Then, in this sense, the parameter has already been passed to its callback function, where the problem is then?

  • Try to start the object: var arrayVelho = {}; Push only works for array.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.