<Button
onPress={{() => Alert.alert(
'Alert Title',
'alertMessage',
[
{text: 'Cancel', onPress: () => console.log('Cancel Pressed!')},
{text: 'OK', onPress: () => {this.onDeleteBTN}},
],
{ cancelable: false }
)}}
>
<Text> Delete Record </Text>
</Button>
警报对话框上的“确定”按钮后 我需要打电话
onDeleteBTN = () => {
alert(' OnDelete');
}
{text: 'OK', onPress: () => {this.onDeleteBTN.bind(this)}},
{text: 'OK', onPress: () => {this.onDeleteBTN}},
这不起作用
答案 0 :(得分:15)
首先,Button
组件有一个title
道具而不是{孩子} <Text>
。第二个问题是你有一堆语法错误,并没有正确调用函数(或绑定)。如果你修复它,那它应该工作正常;例如:
alert = (msg) => {
console.log(msg)
}
onDeleteBTN = () => {
this.alert(' OnDelete')
}
render() {
return (
<View style={styles.container}>
<Button
title="Delete Record"
onPress={() => Alert.alert(
'Alert Title',
'alertMessage',
[
{text: 'Cancel', onPress: () => console.log('Cancel Pressed!')},
{text: 'OK', onPress: this.onDeleteBTN},
],
{ cancelable: false }
)}
/>
</View>
);
}
注意:的
alert()
函数应该做什么,所以我制作了一个记录到控制台的虚拟函数。onDeleteBTN()
或绑定。