gpt4 book ai didi

react-native - 如何在 React Native 中对 Flatlist 的项目执行点击功能

转载 作者:行者123 更新时间:2023-12-05 04:00:21 32 4
gpt4 key购买 nike

我正在获取数据列表,我想在单击平面列表的任何项目时显示每个数据的详细信息,这是我的代码。

 <FlatList style={{paddingBottom:5}}
data = {this.state.fetchFreelancer}
keyExtractor={(y, z) => z.toString()}
renderItem={({ item }) =>

<FreelancerCategory

imageUrifreelancer = {{uri: `${item.profile_img}`}}
imageUrifeatured = {{uri: `${item.badge.badget_url}`}}
featuredColor ={`${entities.decode(item.badge.badget_color)}`}
flagimageUri= {{uri: `${item.location.flag}`}}
freelancername={`${entities.decode(item.name)}`}
title={`${entities.decode(item._tag_line)}`}
rate={`${entities.decode(item._perhour_rate)}`}
country={`${entities.decode(item.location._country)}`}
/>

但是我无法在平面列表中执行 onPress 任何人都可以帮助我解决这个问题。谢谢

它不工作..

<FlatList
style={{ paddingBottom: 5 }}
data={this.state.fetchFreelancer}
keyExtractor={(y, z) => z.toString()}
renderItem={({ item }) => (
<TouchableOpacity
onPress={() => navigate('DetailFreelancerScreen', {profile_id: item.profile_id})}
// onPress={() => alert('Item pressed')}
>
<FreelancerCategory
imageUrifreelancer={{ uri: `${item.profile_img}` }}
imageUrifeatured={{ uri: `${item.badge.badget_url}` }}
featuredColor={`${entities.decode(
item.badge.badget_color
)}`}
flagimageUri={{ uri: `${item.location.flag}` }}
freelancername={`${entities.decode(item.name)}`}
title={`${entities.decode(item._tag_line)}`}
rate={`${entities.decode(item._perhour_rate)}`}
country={`${entities.decode(item.location._country)}`}
/>
</TouchableOpacity>
)}
/>

最佳答案

如果你想执行点击事件,你应该用 TouchableOpacity 或 TouchableWithoutFeedback 覆盖你的项目。

<FlatList 
style={{paddingBottom:5}}
data = {this.state.fetchFreelancer}
keyExtractor={(y, z) => z.toString()}
renderItem={({ item }) => (
<TouchableOpacity
onPress={() => this.props.navigation.navigate('DetailFreelancerScreen',
{profile_id: item.profile_id})}
>
<FreelancerCategory
imageUrifreelancer = {{uri: `${item.profile_img}`}}
imageUrifeatured = {{uri: `${item.badge.badget_url}`}}
featuredColor ={`${entities.decode(item.badge.badget_color)}`}
flagimageUri= {{uri: `${item.location.flag}`}}
freelancername={`${entities.decode(item.name)}`}
title={`${entities.decode(item._tag_line)}`}
rate={`${entities.decode(item._perhour_rate)}`}
country={`${entities.decode(item.location._country)}`}
/>
</TouchableOpacity>
);
/>

有关更多信息,请参阅 RN official document

关于react-native - 如何在 React Native 中对 Flatlist 的项目执行点击功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56270837/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com