我有以下代码:
<SafeAreaView style = {styles.container}>
<FlatList
data={todoData}
renderItem={({ item }) => (
<View style = {styles.buttonContainer}>
<TouchableOpacity
onPress = {console.log(item.id)}
style = {styles.button}
>
<Text style={styles.text}>{item.id}</Text>
</TouchableOpacity>
</View>
)}
/>
</SafeAreaView>
这是页面现在的样子:
它对按钮有效,但我想安慰。当我按下按钮时,记录按钮内的值,但当我按下该按钮时,什么都不会发生。但如果在onPress中,我写console.log("Hello"),我会在控制台中得到单词Hello。在这种情况下,如何登录item.id?
这个item来自我对firebase实时数据库的查询。