【问题标题】:Save DZ.api response in variable将 DZ.api 响应保存在变量中
【发布时间】:2016-11-17 13:38:23
【问题描述】:

使用下面的代码,我可以在函数(响应)部分获得 console.log 响应,但在第二个 console.log 中却没有。使用 dzSearch 函数时,如何将该字符串从 DZ.api 中提取到子/任何变量中?

@Injectable()
export class DeezerService{
  child:any;

  constructor(){
    new DZ.init({
      appId  : 'APPID',
      channelUrl : 'https://localhost:4200/src/channel.html'
    });
  }

  dzSearch(){
    console.log('Testing dzSearch() init');
    this.child = DZ.api('/album/12720342/tracks', function(response){
      console.log(response.data[0].title)
      return response.data[0].title;
      });

    console.log(this.child);
  }
}

【问题讨论】:

    标签: javascript angular deezer


    【解决方案1】:

    请考虑在您的 dzSearch 函数中使用回调。

    这是我的代码:

        searchTrack(query, callback) {
            let result = {};
            DZ.api('/search?q=' + query, (response) => {
                result = this.getFormattedTrack(response);
                if (typeof callback === "function") {
                    callback(result);
                }
            });
        }

    【讨论】:

      猜你喜欢
      • 2018-06-27
      • 2013-04-26
      • 2014-11-09
      • 1970-01-01
      • 2016-03-31
      • 2021-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多