【发布时间】:2019-08-29 04:54:15
【问题描述】:
在我的 Expo 应用程序中,我创建了一个从符号中获取信息的平面列表 符号的值只是硬编码如下
constructor(props) {
super(props)
this.state = {
symbols: [{"symbol": "1816ABC","Name": "Some data","icon": "md-star-outline"}],
}
}
这是我的渲染函数
render() {
if (!this.state.fontLoaded) {
return <Expo.AppLoading />;
}
return (
<View style={styles.mainContainer}>
<View style={{paddingVertical: padding.med,alignItems: 'center'}}>
<Text style={styles.headerText}>
ALERTS
</Text>
</View>
<FlatList
data={this.state.symbols}
extraData={this.state.symbols}
keyExtractor={(item, index) => item.symbol}
ItemSeparatorComponent={this.renderListSeparator}
renderItem={this.renderListItem}
onRefresh={() => this.onPullToRefresh()}
refreshing={this.state.isFetching}
/>
</View>
);
}
当symbols只有1项时,列表不渲染,屏幕空白,只出现ALERTS字样
当我将更多项目硬编码到symbols 列表时,它显示所有项目都没有问题。
不确定这是我的代码还是 FlatList 组件的问题
编辑
renderListItem = ({ item, index }) => {
return (
<TouchableOpacity
onPress={() => this.onPressListItem(index)}
>
<MyListItem
item={item}
/>
</TouchableOpacity>
)
}
编辑 2
【问题讨论】:
-
你会分享
renderListItem吗? -
当然,已经编辑了我的问题
-
你能在snack.expo.io中重现你的错误吗?
-
好的,已添加零食链接
标签: javascript react-native expo react-native-flatlist