Android Studio 提取数据并添加到变量

cfh9epnr  于 2022-12-13  发布在  Android
关注(0)|答案(1)|浏览(156)

你好,我正在处理我的项目,我想把poster_patch取到变量中,以打印我的应用程序中的每一张微缩图像。我正在处理中的react-native。下面是我的应用程序的一些代码。我想创建一个函数来取path_poster的值,并将其添加到uri之后
顶部. js '

import React,{useState,useEffect} from "react";
import { View, StyleSheet, Text } from "react-native";
import MovieBox from './MovieBox';
const API_URL="https://api.themoviedb.org/3/movie/top_rated?api_key=xxx"
export default function Top(){
    const [movies,setMovies]=useState([]);
    useEffect(()=>{
        fetch(API_URL)
        .then((res)=>res.json())
        .then(data =>{
            console.log(data);
            setMovies(data.results);
        })

     }, [])
  return (

    movies.map((movieReq)=><MovieBox key ={movieReq.id} {...movieReq}/>)

  );
};

MovieBox.js

import React from 'react';
import { View, StyleSheet, Text,Image } from "react-native";
const API_IMG = "https://image.tmdb.org/t/p/w500";

function MovieBox ({title, poster_patch,vote_average,release_date,overview}){
const styles = StyleSheet.create({
  container: {
    paddingTop: 50,
  },
  tinyLogo: {
    width: 50,
    height: 50,
  },
  logo: {
    width: 66,
    height: 58,
  },
});
    return(
    <View>
    <Text>
        {title} rated:
        {vote_average}

    </Text>
    <Image source={{
            uri: API_IMG + HERE I WANT TO ADD VARIABLE TO POSTER_PATCH,
            }}
            style={styles.tinyLogo}
            />
    </View>
 )
}
export default MovieBox;

`
如何从poster_path获取值并将其添加到uri中

idv4meu8

idv4meu81#

连接基本url和路径,例如使用concat

<Image source={{
    uri: API_IMG.concat(poster_path),
  }}
  style={styles.tinyLogo}
/>

有关详细信息,请参见Images

相关问题