我试图在平面列表的每个列表末尾添加一个删除按钮。预期的行为是从数组中删除列表。因此,我在press方法上添加了代码,并在警报中检查其是否工作正常。
现在,每当我将一个项目添加到我的平面列表中时,就会弹出此警报。但是在单击我的删除按钮后,弹出窗口没有显示。不确定我是否将其添加到正确的位置。
我是新手,对母语有反应。请帮忙。
<FlatList
data={data.ingredientArray}
width='100%'
extraData={data.ingredientArray}
keyExtractor={(index) => index.toString()}
ItemSeparatorComponent={this.FlatListItemSeparator}
renderItem={({ item }) =>
<View style={styles.TextViewStyle}>
<View style={styles.row}>
<View style={styles.bullet}>
<Text style={{ fontWeight: 'bold', fontSize: 16 }}>{'\u2022' + " "}</Text>
</View>
<View style={styles.bulletText}>
<Text style={{ fontWeight: 'normal', fontSize: 16, color: '#009387' }}>{item.title}</Text>
</View>
<View>
</View>
<Feather
name="x-circle"
color="#009387"
size={30}
onPress={showAlert}
/>
</View>
</View>
} />
我的警报:
const showAlert = () => {
alert('alert me');
}
对此有任何帮助吗?
答案 0 :(得分:1)
您可以将onPress={showAlert}
更改为onPress={() => showAlert()}
??