Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 从API获取日志但不呈现_Reactjs_React Native_React Native Android_React Native Flatlist_React Native Navigation - Fatal编程技术网

Reactjs 从API获取日志但不呈现

Reactjs 从API获取日志但不呈现,reactjs,react-native,react-native-android,react-native-flatlist,react-native-navigation,Reactjs,React Native,React Native Android,React Native Flatlist,React Native Navigation,我一直在尝试从API获取数据,但是日志似乎显示了responseJSON,但是它没有出现在我的前端 这是我获取api的代码: componentDidMount() { return fetch('http://atiiuserauth.ap-south-1.elasticbeanstalk.com/home') .then(response => response.json()) .then(responseJson => { thi

我一直在尝试从API获取数据,但是日志似乎显示了responseJSON,但是它没有出现在我的前端

这是我获取api的代码:

componentDidMount() {
    return fetch('http://atiiuserauth.ap-south-1.elasticbeanstalk.com/home')
      .then(response => response.json())
      .then(responseJson => {
        this.setState(
          {
            isLoading: false,
            data: responseJson,
          },
          console.log(responseJson)
        );
      })
      .catch(error => {
        console.error(error);
      });
  }
这是我的重新设计方法()


请提供帮助,并指出我的错误,如果您需要任何其他详细信息,请告诉我您需要在平面列表中使用
this.state.data.product
,因为产品在json响应的产品字段中

您还需要将数据设置为中的
data
属性,而不是数据源

因此,下面这句话:

datasource={this.state.data}
必须是这样的:

data={this.state.data.product}

您需要在平面列表中使用
this.state.data.product
,因为产品位于json响应的product字段中

您还需要将数据设置为中的
data
属性,而不是数据源

因此,下面这句话:

datasource={this.state.data}
必须是这样的:

data={this.state.data.product}
 render() {
    const { height } = Dimensions.get('window');
    const { width } = Dimensions.get('window');
    const like = this.state.liked ? 'red' : 'white';

    if (this.state.isLoading) {
      return (
        <View style={{ flex: 1, padding: 20 }}>
          <ActivityIndicator />
        </View>
      );
    }

    return (
      <View style={{flex:1}}>

        <FlatList
        datasource={this.state.data}

        renderItem={({ item }) => (
        <View style = {{alignContent: 'stretch'}}>
        <Video 
          source={{ uri: item.urlVid }}
          resizeMode = "cover"
          style={{width: "100%", height: 800}}
        />
         <View
              style={{
                position: 'absolute',
                flexDirection: 'column',
                alignItems: 'flex-end',
                top: '50%',
                right: 10,
              }}>
              <TouchableOpacity
                onPress={this.handleClick}
                style={{
                  alignItems: 'center',

                  borderRadius: 60,
                  padding: 10,
                }}>
                <Icon
                  name="heart"
                  size={30}
                  color={this.state.buttonColor}
                  onPress={this.onButtonPress}
                />
              </TouchableOpacity>


              <TouchableOpacity
                style={{
                  alignItems: 'center',

                  borderRadius: 60,
                  padding: 10,
                }}>
                <Icon name="share" size={30} color="white" />
              </TouchableOpacity>
              <Text style={{ right: 5, color: 'white' }} />
              <TouchableOpacity
                style={{
                  alignItems: 'center',

                  borderRadius: 60,
                  padding: 10,
                }}>
                <Icon name="whatsapp" size={30} color="white" />
              </TouchableOpacity>
              <Text style={{ right: 5, color: 'white' }} />
              <TouchableOpacity
                style={{
                  alignItems: 'center',

                  borderRadius: 60,
                  padding: 10,
                }}>
                <Icon name="download" size={30} color="white" />
              </TouchableOpacity>
              <Text style={{ right: 5, color: 'white' }} />
            </View>
            <View
              style={{
                position: 'absolute',
                flexDirection: 'column',

                top: '90%',
                left: 10,
              }}>
              <View
                style={{
                  flexDirection: 'row',
                }}>
                <Text
                  style={{ fontWeight: 'bold', fontSize: 20, color: 'white' }}>
                  {item.title} - {item.price}
                </Text>



              </View>

            </View>

        </View>


        )}
        ListHeaderComponent={this.header}
        stickyHeaderIndices={[0]}
        keyExtractor={ item => item.id}
      />

      </View>
    );
  }
}
 LOG  {"product": [{"__v": 0, "_id": "5e30067e667d8473f8e79726", "color": "sasasa", "colors": [Array], "description": "sassa", "nameImg": "apex-legends-logo-1580205687689.jpg", "nameVid": "videoplayback-1580205687690.mp4", "sellerID": "sasa", "sellerName": "sasa", "size": "sasa", "sizes": [Array], "title": "wqw", "typeImg": "image/jpeg", "typeVid": "video/mp4", "uploadedOn": "2020-01-28T10:01:34.987Z", "urlImg": "https://atiiproductmediafiles.s3.ap-south-1.amazonaws.com/apex-legends-logo-1580205687689.jpg", "urlVid": "https://atiiproductmediafiles.s3.ap-south-1.amazonaws.com/videoplayback-1580205687690.mp4"}, {"__v": 0, "_id": "5e301696f75182463c6874ed", "color": "Space Grey", "colors": [Array], "description": "apple", "nameImg": "61jgfLBydjL._SL1024_-1580209807807.jpg", "nameVid": "videoplayback (1)-1580209807809.mp4", "price": 99900, "sellerID": "13755902031", "sellerName": "Appario", "size": "5.8-inch", "sizes": [Array], "title": "Apple iPhone 11 Pro", "typeImg": "image/jpeg", "typeVid": "video/mp4", "uploadedOn": "2020-01-28T11:10:14.244Z", "urlImg": "https://atiiproductmediafiles.s3.ap-south-1.amazonaws.com/61jgfLBydjL._SL1024_-1580209807807.jpg", "urlVid": "https://atiiproductmediafiles.s3.ap-south-1.amazonaws.com/videoplayback+%281%29-1580209807809.mp4"}, {"__v": 0, "_id": "5e30171df75182463c6874ee", "color": "Haze Blue", "colors": [Array], "description": "oneplus", "nameImg": "61FRLa8IFTL._SL1500_-1580209943294.jpg", "nameVid": "videoplayback-1580209943295.mp4", "price": 53999, "sellerID": "13755902031", "sellerName": "OnePlus", "size": "6.67 inch", "sizes": [Array], "title": "OnePlus 7T Pro", "typeImg": "image/jpeg", "typeVid": "video/mp4", "uploadedOn": "2020-01-28T11:12:29.918Z", "urlImg": "https://atiiproductmediafiles.s3.ap-south-1.amazonaws.com/61FRLa8IFTL._SL1500_-1580209943294.jpg", "urlVid": "https://atiiproductmediafiles.s3.ap-south-1.amazonaws.com/videoplayback-1580209943295.mp4"}], "user": {"__v": 0, "_id": "5e300846241a3b1c89d654c4", "address": [], "changes": [], "checkout": [], "like": [], "mobile": 8697779335, "registeredOn": "2020-01-28T10:09:10.569Z"}}