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.

2
  • Possible duplicate of jQuery ajax return value Commented Apr 8, 2016 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. Commented Apr 9, 2016 at 1:11

2 Answers 2

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);
        },
    });
Sign up to request clarification or add additional context in comments.

Comments

-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;
},

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.