简体   繁体   English

如何在FlatList React Native中显示JSON数据

[英]How to display JSON data in FlatList React Native

I send request to my API and it return response that i convert it to JSON as below 我将请求发送到我的API,它返回响应,如下所示将其转换为JSON

在此处输入图片说明

now i want to display this JSON in FlaList 现在我想在FlaList中显示此JSON

I'm Trying to do this but it doesn't display anything 我正在尝试执行此操作,但未显示任何内容

<FlatList

          data={this.state.dataSource}
          renderItem={({item}) => <Text> {item.Begin} </Text> }

you need to put Text tag inside a View Tag and also keyExtractor 您需要将“文本”标签放置在“视图”标签以及keyExtractor中

 import React, { Component } from 'react';
 import { Platform, StyleSheet, Text, View, FlatList, Image, ScrollView, Picker } from 'react-native';

 export default class Test extends Component {
  constructor() {
  super();
   this.state = {
    data : [
    {"Begin" : "08:00:00" ,End : "08:10:00"},
    {"Begin" : "08:10:00" ,End : "08:20:00"},
    {"Begin" : "08:20:00" ,End : "08:30:00"},
    {"Begin" : "08:30:00" ,End : "08:40:00"},
    {"Begin" : "08:40:00" ,End : "08:50:00"},
    {"Begin" : "08:50:00" ,End : "08:60:00"},
  ]
  }
}

_keyExtractor = (item, index) => item.Begin.toString();

render() {

 return (
   <View style={{flex:1,justifyContent:'center'}}>
   <FlatList
   data={this.state.data}
   keyExtractor={this._keyExtractor}
   renderItem={({item}) => <Text> {item.Begin} </Text> }
   />
   </View>
  )
 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何在我的React Native FlatList中显示2维JSON数据 - How I can display 2 Dimensional JSON Data to my React Native FlatList 用 json 数据填充平面列表,在本机反应中,不可能? - Populating a flatlist with json data, in react native, not possible? 如何使用 map 在 react native 而不是 FlatList 中获取 JSON 数据对象。 ScrollView 在 FlatList 中不起作用 - How to use map to fetch JSON data objects in react native instead of FlatList. ScrollView is not working in FlatList React Native FlatList 中的 JSON - JSON in React Native FlatList React Native:Flatlist 不适用于 json - React Native: Flatlist not working with json 如何在本机反应中呈现 FlatList 中的数据,我可以控制台记录它但在屏幕上显示它时出现问题 - How to render data in FlatList in react native, I can Console log it but have a problem to display it on Screen 在 React-Native 中为 FlatList 获取和分组 JSON 数据 - Fetch and group JSON data for FlatList in React-Native FlatList 不呈现来自 json 数组 React-native 的数据 - FlatList not rendering data from json array React-native 反应本地平面列表特定数据 - React Native flatlist specific data 如何在 React Native 中将 JSON 嵌套对象映射到平面列表? - How to map JSON nested object to flatlist in react native?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM