我有一个页面,在其中列出人员及其信息。我使用 Flatlist 来渲染我得到的 n 个数据以及分页。
<FlatList
showsVerticalScrollIndicator={false}
data={this.state.records}
keyExtractor={(item) => String(item.ServiceRequestID)}
renderItem={({ item }) => (
<View>
<ImageBackground
source={{ uri: this.state.baseUserImagePath + item.ImagePath }}
style={styles.image}
imageStyle={{ borderRadius: h2p(48) }}
/>
//other parts
</View>
)}
onEndReached={()=>{//logic}}
/>
我希望为无法加载的图像加载默认用户图像(在我的情况下在本地服务器中删除)。所以,我想在图像背景中添加 onError 属性。对于单个图像,我可以使用
onError={() => {this.setState({ image: require('../../assets/user.png') });}}
并使用source={this.state.image}
如何为 Flatlist 中的图像执行此操作以处理我的情况。