Javascript Axios采用瀑布式方式

Javascript Axios采用瀑布式方式,javascript,promise,axios,Javascript,Promise,Axios,我有一个类似于下面的JSON,需要创建一个数据结构,通过从JSON中的链接获取历史记录和个人详细信息来获得用户的完整配置文件。有没有想过如何使用axios进行此操作 JSON={ 0:{ userid:"...", details:"http:://<user>/profile", history:"http://<user>/history" } 1:{

我有一个类似于下面的JSON,需要创建一个数据结构,通过从JSON中的链接获取历史记录和个人详细信息来获得用户的完整配置文件。有没有想过如何使用axios进行此操作

JSON={
      0:{
          userid:"...",
          details:"http:://<user>/profile",
          history:"http://<user>/history"
      }
      1:{
          userid:"...",
          details:"http:://<user>/profile",
          history:"http://<user>/history"
      }
      2:{
          userid:"...",
          details:"http:://<user>/profile",
          history:"http://<user>/history"
      }
    }
JSON={
0:{
用户ID:“…”,
详细信息:“http::///profile”,
历史:http:///history"
}
1:{
用户ID:“…”,
详细信息:“http::///profile”,
历史:http:///history"
}
2:{
用户ID:“…”,
详细信息:“http::///profile”,
历史:http:///history"
}
}
期望的结果是json

  JSON:{
    0:{
        userid:"1",
        name:"<datafrom profile>",
        age:"<data from profile>",
        last_login:"<data from history>"
    },
    1:{
        userid:"1",
        name:"<datafrom profile>",
        age:"<data from profile>",
        last_login:"<data from history>"
    },
    2:{
        userid:"2",
        name:"<datafrom profile>",
        age:"<data from profile>",
        last_login:"<data from history>"
    },
   }
JSON:{
0:{
用户标识:“1”,
姓名:“,
年龄:“,
上次登录:“
},
1:{
用户标识:“1”,
姓名:“,
年龄:“,
上次登录:“
},
2:{
用户标识:“2”,
姓名:“,
年龄:“,
上次登录:“
},
}

假设详细信息和历史键值对是合法的URL。我将使用
http://someDataUrl.com
http://someHistoryUrl.com
在本例中

另外,我也不确定端点会返回什么,所以我编了一些例子

function getDataInfo(user){
  return axios.get(`http://someDataUrl.com/${user}`)
}

function getHistoryInfo(user){
  return axios.get(`http://someHistoryUrl.com/${user}`)
}

let json = {}
axios.all([getDataInfo(), getHistoryInfo()])
  .then(axios.spread(function (data, history) {
    // use response from each to populate data object literal. Something like this? :
    json.name = data.name
    json.last_login = history.last_login
  }));

谢谢安德鲁。这真的给了我一个想法。我刚刚更新了问题陈述。非常感谢您的帮助似乎您想使用json请求将第一个示例中的数据映射到第二个示例?是的,我需要迭代获取第一个json中的链接以创建第二个json链接,您只需循环遍历数据,然后使用类似于我为每个索引提供的函数的内容