e头调用Alert onPress并在React Native中发送其中的一些参数 [英] Hoe to call Alert onPress and send some parameter in that in react native
本文介绍了e头调用Alert onPress并在React Native中发送其中的一些参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这里,我在文本字段上调用alart函数onPress。
在调用该功能时,我试图打开警报并在确认时在调用其他功能。
但是如果我打电话给 showAlert1(),它就会变得挂起。该函数多次调用
我必须调用showAlert()函数onPress,并且必须在中发送一些值。然后在Alert的确认OK按钮上,我必须上传到服务器。
Here I am calling on alart function onPress on text field . On calling that fucntion I am trying to open alert and on confirm I am calling onther fucntion . But its getting hang if I am calling "showAlert1()" . This function is getting call many times I have to call showAlert() function onPress and I have to send some value in in . And on confimation ok button on Alert 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
}
这篇关于e头调用Alert onPress并在React Native中发送其中的一些参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文