如何在React Native上调用Alert onPress并传递一些参数 [英] How to call Alert onPress and pass some parameters in React Native
本文介绍了如何在React Native上调用Alert onPress并传递一些参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这里,我在文本字段上调用警报功能onPress. 在调用该函数时,我试图打开警报并在确认时在调用另一个函数. 但是,如果我调用"showAlert1()",则会挂起. .该函数被多次调用 我必须在showPress上调用showAlert()函数,并且必须在其中发送一些值.然后在警报"框中的确认确定"按钮上,我必须上传到服务器.
Here I am calling on alert function onPress on text field . On calling that function I am trying to open alert and on confirm I am calling another function. But it gets hang if I am calling "showAlert1()" . This function is getting called many times I have to call showAlert() function onPress and I have to send some value in it . And on confirmation OK button on Alert box I have to upload to server.
showAlert1(code, name, version) {
console.log("data alaert abc", code, name, version);
Alert.alert(
'Confirmation',
'Are you sure you want to migrate this tariff',
[
{
text: 'Cancel',
onPress: () => console.log('Cancel Pressed'),
style: 'Cancel',
},
{ text: 'Proceed', onPress: () => this.confirmTariffMigration(code, name, version) },
]
);
}
confirmTariffMigration = (code, name, version) => {
console.log("hhhhdhhdhdhdhhdd", code, name, version);
const objData = {
addofferingActionCode: '',
offeringCode: '',
offeringName: ''
}
this.props.updateTariffMigration(objData)
}
<View style={{ marginLeft: 5, marginRight: 5, marginTop: 10, backgroundColor: '#f1f1f1' }}>
{
tariffMigrationData.map((data, index) => {
return (
// <TouchableOpacity key={index} onPress={this.showAlert1(data)}>
<View style={{ marginBottom: 10, marginLeft: 5, marginRight: 5 }} key={index}>
<Card>
<CardItem header style={{ backgroundColor: '#fff', width: '100%', justifyContent: 'space-between', borderBottomColor: '#f1f1f1', borderBottomWidth: 1 }}>
<View style={{ flexDirection: 'column', justifyContent: 'space-between' }}>
<View>
<RegularText text={`${data.offering.name}`} style={{ fontWeight: 'bold' }} />
<SmallText text={` ID ${data.offering.code}`} textColor="grey" />
</View>
</View>
<View style={{
backgroundColor: 'blue',
borderRadius: 75, height: 25, paddingRight: 10, paddingLeft: 10, paddingTop: 5
}}>
<SmallText text={'Proceed'} onPress={this.showAlert1(data.offering.code, data.offering.version, data.offering.name)} textColor='white' />
</View>
</CardItem>
</Card>
</View>
)
}
}
</View>
推荐答案
尝试更改:
<TouchableOpacity key={index} onPress={this.showAlert1(data)}>
到
<TouchableOpacity key={index} onPress={() => this.showAlert1(data)}>
还有
showAlert1 (code,name,version) {
// code
}
收件人
showAlert1 = (code,name,version) => {
// code
}
这篇关于如何在React Native上调用Alert onPress并传递一些参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文