[英]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.