如何使用地图功能渲染图像?

时间:2020-06-22 19:45:44

标签: image react-native url rendering map-function

我尝试从URL渲染图像,但没有成功。如果写URI正确,但是如果我写item.show.image.original.replace ('http:', 'https:')来获取图像,则不会成功。

问题在于没有错误,但没有渲染。

我成功的其他价值观。

import React, { Component } from "react";
import { Text, View, Image } from "react-native";

let termo = 'batman';
const API = 'http://api.tvmaze.com/search/shows?q='+termo;

export default class mapFunction extends Component {
  constructor(props) {
    super(props);
    this.state = {
      array: [], };
    }

  componentDidMount() {
    fetch(API)
      .then(response => response.json())
      .then(data => this.setState({ array: data}));
  }

  list = () => {
    return this.state.array.map(item => {
      return (
      <View style={{marginLeft: 10}}>
                   <Text>{item.score}</Text>
                   <Text>{item.show.name}</Text>
                   <Text>{item.show.type}</Text>
                    <Text>{item.show.language}</Text>
                   <Text>{item.show.summary} </Text>
                  <Image source={{uri:'https://static.tvmaze.com/uploads/images/original_untouched/6/16463.jpg'}}
                  style={{width:90, height:150}} />
       </View>
      );
    });
  };

  render() {
    return <View>{this.list()}
   
     </View>;
  }
}

1 个答案:

答案 0 :(得分:0)

只需更改渲染功能,如下所示:

render() {
    return (
       <View>{this.list()}</View>
    );
}
相关问题