【问题标题】:json got changed when consuming it via a promise (aws api gatway SDK)json 在通过 promise 使用时发生了变化(aws api gateway SDK)
【发布时间】:2018-03-20 09:29:24
【问题描述】:

我正在使用 AWS API Gateway 为 Angular 4 中的项目生成 js SDK,我正在使用 sdk 调用端点并成功获取数据。在浏览器的网络选项卡中,显示的数据是正确的,当我使用 promise 使用相同的数据时

.then( response => { console.log(response); }

在控制台打印的数据和网络选项卡中的数据是不同的——甚至在我将它用于我的项目之前。

AWS API Gateway js SDK 代码:

getFundAdvisesList(fund: string) {
    return this.credentialService.getAwsSDK().adviserFundAdviseGet({
      'adviser': this.credentialService.$id,
      'fund': fund
    }, {}, {});
  }

这是我用来调用上述 SDK 函数并在控制台上打印的代码

this.http.getFundAdvisesList(fund.fundName)
      .then(response => {
        console.log(response); // change in numbers seen in console

这里有几张图片显示了从网络标签到浏览器控制台的数据差异

https://drive.google.com/file/d/0B7HCwcSUzwkGWVRKbmo4cW9BSFk/view?usp=sharing https://drive.google.com/file/d/0B7HCwcSUzwkGRlhVNG1XMXJvQlU/view?usp=sharing

【问题讨论】:

    标签: angular amazon-web-services


    【解决方案1】:

    确切的原因不是没有,而是由于console.log行之后编写的代码。

    并且由于 java-script 默认情况下是异步的 - 打印的数据已被代码的另一部分更改。主要发生在我将接收到的数据数组转换为特定对象(打字稿模型)的那一行

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-06
      • 2018-05-04
      • 1970-01-01
      • 2019-01-07
      • 1970-01-01
      • 2017-04-13
      • 2017-07-09
      相关资源
      最近更新 更多