Javascript 在react native中调用警报后,Ui挂起
// 这里我调用文本字段上的alart函数onPress。 在调用该功能时,我尝试打开警报,在确认后,我调用另一个功能。 但如果我调用“showAlert1()”,它就会被挂起。此函数多次收到调用Javascript 在react native中调用警报后,Ui挂起,javascript,reactjs,react-native,Javascript,Reactjs,React Native,// 这里我调用文本字段上的alart函数onPress。 在调用该功能时,我尝试打开警报,在确认后,我调用另一个功能。 但如果我调用“showAlert1()”,它就会被挂起。此函数多次收到调用 showAlert1 (code,name,version) { console.log("data alaert abc", code,name,version); Alert.alert( 'Confirmation',
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>
{tariffMigrationData.map(
(数据、索引)=>{
返回(
//
当我们想将参数传递给道具时,有两种方法:
this.showAlert1(数据)}>
/////////////////////////////////////
我也这样做了。但不起作用抱歉,这不起作用..按{()=>this.showAlert1(…)如果我正在使用此函数,则无法调用此函数。showAlert1(data.offering.code,data.offering.version,data.offering.name)}textColor='white'/>
when we want to pass params to props, here are two ways:
<TouchableOpacity key={index} onPress={() => this.showAlert1(data)}>
<TouchableOpacity key={index} onPress={this.showAlert1.bind(this,data)}>
/////////////////////////////////////
<TouchableOpacity key={index} onPress={this.showAlert1(data)}>