UI在响应本机中调用Alert后变得挂起

// 在这里,我在文本字段上调用alart函数onPress。 在调用该功能时,我试图打开警报,并在确认时在调用其他功能。 但是如果我打电话给“ showAlert1()”,它就会死机。该函数多次调用

   showAlert1 (code,name,version) {  
        console.log("data alaert abc",code,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,version)},]  
        );  
    }  

 confirmTariffMigration =(code,version) =>{
    console.log("hhhhdhhdhdhdhhdd",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>
t456456 回答:UI在响应本机中调用Alert后变得挂起

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)}>
本文链接:https://www.f2er.com/3160076.html

大家都在问