简体   繁体   中英

Ext.Ajax.request variables

I want to access to some variable(datoslicitproduct) that I declared out ot an Ext.Ajax.request, but I initialize it inside the request. I have this function :

function ExportarExcelproddet(){
var datoslicitaciones = [];
var datoslicitproduct=[];
var datafinal;
var fila=[];
var fila2=[];
var Tipo;
var IdPliego;
ExpGridstore.each(function(r){
    fila.push(r.data['Tipo']);
    fila.push(r.data['IdTxt']);
    fila.push(r.data['Id_Exp']);
    fila.push(r.data['Exp']);
    fila.push(r.data['Org']);
    fila.push(r.data['Fpub'].format('d/m/Y'));
    fila.push(r.data['Fvto'].format('d/m/Y'));
    fila.push(r.data['Estado']);
    datoslicitaciones.push(fila);
    fila=[];
});
var respuestaphp;
var row;
var cont=0;
while(cont<datoslicitaciones.length){
    Tipo=datoslicitaciones[cont][0];
    IdPliego=datoslicitaciones[cont][2];
    Ext.Ajax.request({
        url:'./php/ProductosDetalleExp.php',
        params:{cliente:despliegue,operacion:'lote',tipo:Tipo,id:IdPliego},
        success: function(response){
            respuestaphp=Ext.util.JSON.decode(response.responseText);
            var cont2=0;
            var row;
            while(cont2<respuestaphp['data'].length){
                row=respuestaphp['data'][cont2];
                fila2.push(row['IdExpediente']);
                fila2.push(row['Nro_Orden']);
                fila2.push(row['Nombre_Lote']);
                fila2.push(row['Baja']);
                fila2.push(row['Cotiza']);
                fila2.push(row['TotLicitacionsVat']);
                fila2.push(row['TotOfertasVat']);
                datoslicitproduct.push(fila2);
                fila2=[];
                cont2++;
            }
        }
    });
    cont++;
}
console.log(datoslicitproduct);
}

And when I call console.log(datoslicitproduct); at the end it appears like this in the console: 在此处输入图片说明

And if i try console.log(datoslicitproduct[0]); it says undefined and I dont understand Why. And I want to know how to access to a specific position.

Ext.Ajax.request is asynchrone, which mean it doesnt stop and wait for the return of the request. So your console.log is call before the request return. You have to do this in the "success" callback which is call when the request came back.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM