2016-11-21 15 views
0

quickblox sdkをイオン2アプリに統合しました。 下記のretrieveChatDialogs関数からjsonオブジェクトを取得できませんでしたが、レスポンスでサーバのSPIレスポンスを受信しましたが、変数のチャットスコープはコンソールログに空白を表示します。 私はtypescript 2とangular 2に慣れています。イオン2と角度2変数のスコープの動作が動作しません

export class Quickblox { 
public chats: any; dialogs: any = {}; 
    retrieveChatDialogs() { 
     var _that = this; 
     _that.chats = _that.getdialoglist(); 
     console.log(_that.chats); 
    } 
    getdialoglist(){ 
     var chatdialog:any; 
     chatdialog = QB.chat.dialog.list(null, function (err, resDialogs) { 
      if (err) { 
      console.log(err); 
      chatdialog = {}; 
      } else { 
      chatdialog = resDialogs.items; 
      } 
     }); 
      console.log(chatdialog); 
     return chatdialog; 
    } 

} 
+0

を非同期であるので、 'にconsole.log(chatdialog); 'もちろん、ブランク印刷します。 [** this **](http://stackoverflow.com/questions/23667086/why-is-my-variable-unaltered-after-i-modify-it-inside-of-a-function-asynchron)のトピックを読む詳細については。 – developer033

+0

これは私を助けてくれてありがとう! – cakedev

答えて

0

この試し:機能

retrieveChatDialogs() { 
    var _that = this; 
    _that.chats = _that.getdialoglist(function(){ 
     console.log(_that.chats); 
    }); 
} 
関連する問題