求教一个函数嵌套中断的问题? 第二个函数我是想当成公共函数来调用

小程序 文章 2020-08-11 10:21 476 0 全屏看文

AI助手支持GPT4.0

求教一个函数嵌套中断的问题? 第二个函数我是想当成公共函数来调用Ask for advice on the problem of function nesting interrupt? I want to call the second function as a public function

求教一个函数嵌套中断的问题? 第二个函数我是想当成公共函数来调用

第二个函数我是想当成公共函数来调用

第二个函数为 判断第一个函数输入的值为空,

在第一个函数中调用第二个判断的函数,如何在第二个函数判断第一个函数输入为空时中断并不再执行第一个函数里剩下的代码

  submitChangeFun:function(e){    console.log(e.detail.value.change);    let t = this;    // 输入的值    let changeData = e.detail.value.change;    // 调用判断输入的值是否为空函数    t.publicPopup(changeData);    // 判断不为空时再继续执行    console.log('判断不为空时再继续执行');  },  // 判断输入的值是否为空函数  publicPopup:function(inputData){    if(inputData==""){      wx.showToast({        title'请输入后再点击',        icon:'none'      })      return false;    }  }

The second function I want to call the second function as a common function is to judge the value entered by the first function is empty. In the first function, I call the second judgement function, and how to interrupt the second function when judging the first function is empty, and stop the remaining code in the first function.   submit ChangeFun:function (e){     console.log (e. detail.value.change ); let t = this; / / enter the value let changedata = E detail.value.change ; / / call the function t.publicpopup (changedata) to judge whether the input value is empty; / / continue the execution if it is not empty console.log ('continue to execute if it is not empty ');}, / / judge whether the input value is an empty function PU blicPopup:function (inputData){    if(inputData==""){       wx.showToast ({Title: 'please input and click',         icon:'none'      })      return false;    }  }

回答:

Mr王:

第二个函数判断后return一个true或false,这样第一个函数就知道是不是可以return了

-y😪:

为什么要嵌套呢,你的要求是为空中断

 submitChangeFun:function(e){if(!e.detail.value.change){    return false;          }    let t = this;        // 输入的值    let changeData = e.detail.value.change;       // 判断不为空时再继续执行    console.log('判断不为空时再继续执行');  },


一只大贝贝:我是想写一个公共函数 第二个函数其实是一个公共函数
-y😪:那就直接在公共函数来个三元
-y😪:t.publicPopup(changeData)===false?return :' '
xplee:不是return干的事么?
一只大贝贝:我不知道怎么写正常一个函数里面写个return 不是就终止了么 我是想把第二个函数做为公共函数来使用

-EOF-

AI助手支持GPT4.0