2016-06-30 10 views
0

Ich habe ein Klassen, die,JQuery-Objekt "undefiniert" rufen zunächst

$.row = { 
    rowJson:"1", 
    getRow: function (rowId) { 
     $.ajax({ 
      type: "POST", 
      url: "bla bla post link", 
      data: "{bla bala data}", 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      success: function (dc, status) { $.row.rowJson = JSON.parse(dc.d);}, 
      error: function (request, status) { $.row.rowJson = "-1"; alert(request.responseText) } 
     }); 
    }, 
    success: function() { if (rowJson == "-1") { return false; } else { return true; } }, 
    Id: function() { return rowJson[0].Id;}, 
    Uygulama: function() { return rowJson[0].Uygulama;}, 
    Kullanici: function() { return rowJson[0].Kullanici;}, 
    Seviye: function() { return rowJson[0].Seviye;}, 
    Durum: function() { return rowJson[0].Durum;}, 
    Baslik: function() { return rowJson[0].Baslik;}, 
    TarihSaat: function() { return rowJson[0].TarihSaat;}, 
    Aciklama: function() { return rowJson[0].Aciklama;}, 
    TalepDurumId: function() { return rowJson[0].TalepDurumId;}, 
    UygulamaId: function() { return rowJson[0].UygulamaId;}, 
    TalepSeviyeId: function() { return rowJson[0].TalepSeviyeId;}, 
} 

nachdem ich wie auf diese Weise genannt,

function _rowInfo(rowId) { 
    pWaitShow("Please Wait"); 
    $.row.getRow(rowId); 
    if($.row.success()) 
    { 
     pWaitHide(); 
     console.log([kbJson,$.row.rowJson]) 
    } 
    else 
    { 
     pWaitHide(); 
     $.ms.standartError(); 
    } 
} 

Console Wert ist undefined, wenn ich diese Funktion aufgerufen (_rowInfo(5)) zunächst aber Konsole Wert ist ein reales Objekt, wenn ich diese Funktion aufgerufen habe (_rowInfo(5)) nach dem ersten genannt ich meine sagen zweitens, drittens

+0

Mögliches Duplikat von [Wie gebe ich die Antwort von einem asynchronen Anruf zurück?] (Http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous- call) – Andreas

+0

Ich kann @andr verstehen eas. Tut mir leid, wie ich das nenne? –

Antwort

0

Die Antwort kommt von einem asynchronen Aufruf, so dass man etwas tun sollte, dieses Verhalten zu umgehen:

können Sie ändern die getRow Funktion wie folgt aus:

getRow: function(rowId, callback) { 
    $.ajax({ 
    type: "POST", 
    url: "bla bla post link", 
    data: "{bla bala data}", 
    contentType: "application/json; charset=utf-8", 
    dataType: "json", 
    success: function(dc, status) { 
     rowJson = JSON.parse(dc.d); 
     callback(rowJson); 
    }, 
    error: function(request, status) { 
     rowJson = "-1"; 
     alert(request.responseText) 
     callback(rowJson); 
    } 
    }); 
}, 

und ändern Sie Ihre _rowInfo zu:

function _rowInfo(rowId) { 
    pWaitShow("Please Wait"); 
    $.row.getRow(rowId, function(row) { 
    if($.row.success()) 
     pWaitHide(); 
     console.log([kbJson, row]) 
    } else { 
     pWaitHide(); 
     $.ms.standartError(); 
    } 
    }); 
} 
+0

Ja Entschuldigung Überprüfen Sie meine letzte Änderung, ich ersetzt 'if (row.success)' bis 'if ($. Row.success())' –

+0

Vielen Dank mucj @QuentinRoger Ich wünsche guten Tag und ein gutes Leben für Sie –

+0

I ' m froh, dass das geholfen hat;) –