Fetch post 请求

#1

大家下午好,请教一个问题
http post 请求里 我想循环取到多个接口的数据,url是固定的,body 里传入的 building 跟 floor 参数不一样,想让他通过一次请求 .then之后 返回一个数组,请问怎么让参数

[ {building:'810',floor:'110'},{building:'830',floor:'120'} ] 

循环下面的 fetch 返回一个数组

fetch("http://xxx", {
    method: 'POST',
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    },
    body: JSON.stringify({
      "building": building,
      "floor": floor,
    })
  }).then(res => res.json()).then(json => {这里想得到一个数组}
#2

Promise
去峰哥那看看就明白了

#3

方便贴个链接吗

#4

没有一个能解答的吗?

#5

把feach抽成函数,[ {building:‘810’,floor:‘110’},{building:‘830’,floor:‘120’} ]用map方法处理

#6

目前就是这么做的 不行 - -

#7

没有看明白问题在哪里?

#8

现在是循环请求接口,但是每一个返回来的json 是对象,我想每一个返回来的json 变成数组

#9

用promise all 应该满足需求

#10

fetch 本身没有提供这种功能
只能自行发起多个请求,然后concat成一个数组

#11