判断语句怎么使用?

发布于 9 年前作者 hexia7344 次浏览最后编辑 9 年前来自 issues
data: {
   or:'false',
   ors:false,
   userInfo: {},
   inputValue:''
 },
 
 //实时写入宿舍号
 bindKeyInput: function (e) {
   this.setData({
     inputValue: e.detail.value
   })
 },
 //表单提交处理
 formSubmit: function (e) {
   console.log('form发生了submit事件,携带数据为:', e.detail.value)   
   var inputValues = this.data.inputValue;
   try {
     wx.setStorageSync('ssh', inputValues)
     //初始化数据库       
     const db = wx.cloud.database()
     //获取记录
     db.collection('dormitory').where({
       hostel: this.data.inputValue
     }).get().then(res => {
       this.setData({
         ors:true
       })
       })
       if(!this.data.ors){
         wx.showToast({
           title: '您输入的宿舍号有误,请重新输入',
           icon: 'none'
         })
       }else{
         wx.redirectTo({
           url: 'detail/details',
         })
       }
   } catch (e) {       }
       
    
 
    
      
    
 },

输入错误的数据时,点击查询,第一次判断进入wx.showToast方法了,但是再点一次就直接进入wx.redirectTo方法跳转了。怎么回事?数据没有改动,appdata中ors的仍然是false。

5 回复
hzou
hzou1 楼6 年前

代码没看见有语法错误的问题,所以我跟楼上 有脾气的酸奶 想的一样

wanjie
wanjie2 楼6 年前

自己都已经设置为true了

guiyingwei
guiyingwei3 楼6 年前

debugger 是个好东西,建议用起来

zhenglei
zhenglei4 楼6 年前

你先这样 然后再这样 最后这样 就行了

mengping
mengping5 楼6 年前

this在外部定义一下 let that = this;this.setData({})