【发布时间】:2019-04-06 09:41:11
【问题描述】:
我无法显示我的平面列表,并且我不确定我的编码是否正确。如果我运行它时没有输出。它只会显示一个白屏。我的数据是正确的,即 this.props.section.songs。我想在我的文本中显示标题和艺术家,但我做不到。
export default class SongList extends Component
{
renderSongsList() {
return(
<View>
<FlatList
data = {this.props.section.songs}
renderItem={(song, sectionId, rowId) => (
<TouchableOpacity onPress={ () => Actions.Player({songIndex: parseInt( rowId ),songs: this.props.section.songs, section: this.props.section }) }>
<View key={song} style={ styles.song }>
<Text style={styles.itemTitle}>
{ song.title}
</Text >
<Text style={styles.itemArtist}>
{ song.artist }
</Text>
</View>
</TouchableOpacity>
)}
/>
</View>
);
}
render()
{
return (
<View>
{ this.renderSongsList() }
</View>
);}}
【问题讨论】:
-
请仔细检查您在渲染行方法中的歌曲变量中收到了什么... flatList 提供变量 {item} 中的数据项,您必须销毁它。
标签: react-native react-native-flatlist