1

I have a function with a store load. That is:

function PdCtrl_Posicionamiento_RegistrarPosicion(numeroPrograma, tren, fechaTren, ramal, secuenciaEstacion, kilometraje, hora, minuto, tipoOrigen, eliminaDependencia) {



storePdCtrl_Posicionamiento_RegistrarPosicion.load({
    params: {
        numeroPrograma: numeroPrograma,
        tren: tren,
        fechaTren: fechaTren,
        ramal: ramal,
        secuenciaEstacion: secuenciaEstacion,
        kilometraje: kilometraje,
        hora: hora + ":" + minuto,
        tipoOrigen: tipoOrigen,
        eliminaDependencia: eliminaDependencia,
        usuario: NOMBRE
    },
    callback: function () {

        var estado = new Array();
        var err = storePdCtrl_Posicionamiento_RegistrarPosicion.getAt(0).get('ESTADO');
        var mensaje = storePdCtrl_Posicionamiento_RegistrarPosicion.getAt(0).get('MENSAJE');

        estado.push(err);
        estado.push(mensaje);

        return estado;
    },

});

}

And I need to get the returned value (the array) in other place (in the function call) but for the way that ExtJs works (async), I can't get the array. The following lines don't work:

var vl_estado = PdCtrl_Posicionamiento_RegistrarPosicion(numeroPrograma, tren, fechaTren, ramal, secuenciaEstacion, kilometraje, hora, minuto, tipoOrigen, eliminaDependencia);
    console.debug("estado:" + vl_estado);

When I debug the variable "estado" I don't have any value. Maybe I don't explain the situation in a good way. Sorry and thanks.

  • Possible duplicate of [jQuery ajax return value](http://stackoverflow.com/questions/4982983/jquery-ajax-return-value) – Evan Trimboli Apr 08 '16 at 22:31
  • Set the load handler to a wrapper function which calls the store load method. This will allow you work with a variable scope within the wrapper method which you can access and set when the callback fires. – Hardrada Apr 09 '16 at 01:11

2 Answers2

0

you thinking on wrong way. you just call a method at the end of your callback method with your variable.

Just like this;

var doSomeThingWithVariable = function(passedVariable){
     alert(passedVariable);
};    
storePdCtrl_Posicionamiento_RegistrarPosicion.load({
        params: {
            numeroPrograma: numeroPrograma,
            tren: tren,
            fechaTren: fechaTren,
            ramal: ramal,
            secuenciaEstacion: secuenciaEstacion,
            kilometraje: kilometraje,
            hora: hora + ":" + minuto,
            tipoOrigen: tipoOrigen,
            eliminaDependencia: eliminaDependencia,
            usuario: NOMBRE
        },
        callback: function () {

            var estado = new Array();
            var err = storePdCtrl_Posicionamiento_RegistrarPosicion.getAt(0).get('ESTADO');
            var mensaje = storePdCtrl_Posicionamiento_RegistrarPosicion.getAt(0).get('MENSAJE');

            estado.push(err);
            estado.push(mensaje);

            doSomeThingWithVariable(estado);
        },
    });
Umut
  • 176
  • 1
  • 7
-1

Have you tried:

callback: function (records) {
    if (records.length > 0) {
        var estado = new Array();
        var err = records[0].get('ESTADO');
        var mensaje = records[0].get('MENSAJE');
        estado.push(err);
        estado.push(mensaje);
        return estado;
    } else {
        return null;
},
Elcid_91
  • 1,571
  • 4
  • 24
  • 50