【问题标题】:How to make many functions by onPress according to index?onPress如何根据索引做很多功能?
【发布时间】:2019-11-10 16:34:51
【问题描述】:

我有一张地图,如果我在每个项目上按索引制作功能,我想要

  <ActionSheet
            ref={o => this.ActionSheet = o}
            title={'Which one do you like ?'}
            options={['Delete', 'Edit','Hide', 'Cancel']}
            cancelButtonIndex={3}
            destructiveButtonIndex={1}
           onPress={(index) => { ?????????}
          />

我想如果我按下 index=0 使这个函数 >>this.delete 如果索引 = 1,则执行此功能 >>Actions.editpost.. 我该怎么做??

【问题讨论】:

  • 创建函数是什么意思?你的意思是调用一个函数?还是实际构造一个函数定义?
  • 调用函数

标签: react-native


【解决方案1】:

你可以直接调用如下函数:




       deleteFunction = () =>{
          console.log('write your delete functionality');
          console.log('you can use ref this.ActionSheet.show()');
        }

        editFunction = () =>{
          console.log('write your edit functionality');
        }

    render(){
     return(


          <ActionSheet
                    ref={o => this.ActionSheet = o}
                    title={'Which one do you like ?'}
                    options={['Delete', 'Edit','Hide', 'Cancel']}
                    cancelButtonIndex={3}
                    destructiveButtonIndex={1}
                    onPress={(index) => {
                     if(index === 0){
                       this.deleteFunction();
                     }else if(index === 1){
                       this.editfunction();
                     }
                   }
                  />
      )
    }


【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-08
    • 2020-11-22
    • 2020-09-11
    • 2019-03-29
    相关资源
    最近更新 更多