【问题标题】:Chaining promises to stop nesting [closed]链接承诺停止嵌套[关闭]
【发布时间】:2017-06-15 05:36:05
【问题描述】:

大家好,我想兑现我的承诺。

【问题讨论】:

  • 你在哪里return objects - 当然,它将是一个空数组,因为需要完成异步代码才能添加到objects

标签: javascript json node.js promise


【解决方案1】:

在第一个代码块中尝试以下操作

getUrls('https://json', 25, true)
.then((result) => {
    return Promise.all(result.map(url => getJSONObject(url)));
}).then((objects) => {
    console.log(objects); // issue just shows empty []
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-24
    • 2014-12-29
    • 1970-01-01
    • 2019-05-10
    • 2017-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多