【发布时间】:2017-07-29 08:39:26
【问题描述】:
这样做的目的是在继续之前循环请求几次。 github.repos.getBranch 应该先构建一个包含 10 个元素的对象,然后我才能继续使用结果。
github api 请求按预期工作,但结果记录在:console.log('++', res) 返回以下内容:++ [ undefined, undefined, undefined, undefined, undefined ]。
如果我在循环结束后登录allBranches,数据就在那里。
在 github 请求之后,我显然错过了一步。我已经尽我所能地重构了它,但没有成功。
getAllData: () => {
let allBranches = []
let startGetData = config.repositories.map(repo => {
config.branches.map(branch => {
return allBranches.push(
github.repos.getBranch({
owner: config.organisation,
repo,
branch
})
)
})
})
return Promise.all(startGetData)
.then(res => {
console.log('++', res)
})
}
【问题讨论】:
-
你想要什么结果?我猜是一个存储库数组,其中每个条目都是一个分支数组?
-
(另请注意,github API 是有速率限制的,但我猜要么您没有进行那么多调用,要么您已将自己列入白名单。)
-
正如你所说,我想要一个存储库数组,其中每个存储库都是一个分支数组。基本上是将暂存分支与主分支进行比较,看看哪个更新。这是一个方便的工具,没有很多请求。到目前为止,只有我,我是这里唯一的问题。
-
好的,我已经更新了我的答案,以展示你这样做的一种方式。
标签: javascript loops promise