Javascript 如何传递一个URL的JSON响应并将其传递到另一个JSON URL以获取结果?
我正在尝试从这个JSON URL访问所有“landscapePosterId”。在上述URL的JSON响应中: “landscapePosterId”是imageID。我想在下面的URL中传递它,以便像这样获取图像 示例:- ,那么如何合并这两个API并访问图像Javascript 如何传递一个URL的JSON响应并将其传递到另一个JSON URL以获取结果?,javascript,json,reactjs,api,Javascript,Json,Reactjs,Api,我正在尝试从这个JSON URL访问所有“landscapePosterId”。在上述URL的JSON响应中: “landscapePosterId”是imageID。我想在下面的URL中传递它,以便像这样获取图像 示例:- ,那么如何合并这两个API并访问图像 这是我的密码“landscapePosterId” 从“React”导入React; 从“Axios”导入Axios; 导入“react responsive carousel/lib/styles/carousel.min.css”;
这是我的密码“landscapePosterId”
从“React”导入React;
从“Axios”导入Axios;
导入“react responsive carousel/lib/styles/carousel.min.css”;//需要一个加载器
从“反应响应旋转木马”导入{Carousel};
类滑块扩展了React.Component{
构造函数(){
超级();
此.state={
数据:[]
}
}
异步组件didmount(){
const response=等待Axios.get(“http://staging.connectingdotsinfotech.com:8080/firestixAPI_dev_2/api/v2/media/fetchAllMediaSlider")
。然后((响应)=>{
//console.log(response.data)
这是我的国家({
数据:response.data
})
})
}
异步组件didmount(){
常量响应=等待Axios.post(“”)
}
render(){
报税表(
{
this.state.data.map((项,索引)=>{
返回(
{item.landscapePosterId}
)
})
}
)
}
}
导出默认滑块;
在第一次提取之后,您就拥有了为图像构建src URL以馈送到旋转木马所需的所有内容。映射您收到的数据,并对其进行分解,以构建src url。在这里,我还对react key的id
和description
进行了分解,并对image alt text标记进行了可访问性分析
render(){
const{data}=this.state;
返回(
{data.map({description,id,landscapePosterId})=>(
))}
);
}
可能会有帮助。您是否需要立即获取这些图像,或者只是将图像ID存储在状态中以供以后加载/显示它们?您能告诉我们您迄今为止尝试了什么吗?因为有了这段代码,您似乎不知道如何使用html。但你可以证明我错了。没有api会为您创建图像标记。因此,在div内部创建一个go@DrewReese我想使用这两个API访问图像并将其显示在旋转木马上。从我想要访问所有“landscapePosterId”的第一个API开始,添加到第二个API中以获取结果,在获取结果之后,我想要将该图像显示到第二个API中Carousel@jPO我已经在描述中解释了我想要访问所有“landscapePosterId”并添加到第二个API以获取结果的所有内容,获取结果后,我想在旋转木马上显示该图像谢谢,谢谢,非常感谢现在它运行正常谢谢您的描述它帮助我提高了知识水平
import React from 'react';
import Axios from 'axios';
import "react-responsive-carousel/lib/styles/carousel.min.css"; // requires a loader
import { Carousel } from 'react-responsive-carousel';
class Slider extends React.Component {
constructor() {
super();
this.state = {
data: []
}
}
async componentDidMount() {
const response = await Axios.get("http://staging.connectingdotsinfotech.com:8080/firestixAPI_dev_2/api/v2/media/fetchAllMediaSlider")
.then((response) => {
//console.log(response.data)
this.setState({
data: response.data
})
})
}
async componentDidMount() {
const response = await Axios.post("")
}
render() {
return (
<>
<Carousel>
<div>
{
this.state.data.map((item,index) => {
return (
<div key={index}>
{item.landscapePosterId}
</div>
)
})
}
</div>
</Carousel>
</>
)
}
}
export default Slider;
render() {
const { data } = this.state;
return (
<div className="App">
<Carousel>
{data.map(({ description, id, landscapePosterId }) => (
<img
key={id}
alt={description}
src={`http://staging.connectingdotsinfotech.com:8080/firestixAPI_dev_2/api/v1/files/download/${landscapePosterId}`}
/>
))}
</Carousel>
</div>
);
}