调用数据库后if语句怎么直接跳过了?

小程序 文章 2021-03-29 11:02 497 0 全屏看文

AI助手支持GPT4.0

调用数据库后if语句怎么直接跳过了?Why is the if statement skipped directly after calling the database?

调用数据库后if语句怎么直接跳过了?

res.data是找得到的,然后我想判断数据库里有这条记录就可以继续,没有就跳转到首页去。用if判断的,为什么直接跳过if步骤没有执行呢?求大佬解释。

res.data I can find it. Then I want to judge if there is this record in the database, I can continue. If there is no record, I will jump to the home page. Judging by if, why did you skip the if step and not execute it? Please explain.

回答:

陈宇明:

有信息所以不进if


山楂片真好吃😶:else 我写了会打印“信息存在” 但是也没有打印呀
陈宇明:你也没有截图else代码。。。
山楂片真好吃😶:看不到么... 我帖子里有两张图 然后我还评论了一条完整的代码😭
鲤子:

author不是有数据?你if判断条件不成立当然不会执行里面的代码了。

山楂片真好吃😶:else 我写了打印“信息存在” 但是后台也没有打印 所以我感觉if没有执行啊
山楂片真好吃😶:

onLoad: function (options) {

    that = this

    wx.cloud.callFunction({

      name: 'login'

    }).then(res => {

     var openid=res.result.openid

     db.collection('user').doc(openid).get({

      success: function(res) {

      console.log(res.data[0].author)

      if(res.data[0].author==''){

       wx.showToast({

       title: '请先获取信息',

       icon: 'success',

       duration: 2000,

     })

       wx.switchTab({

       url: '/pages/list/list'

     });}else{console.log('信息存在');}

    }

    })

     that.setData({

         openid: openid})  

         console.log(openid)

         

    }),

    that.jugdeUserLogin()

  },


-EOF-

AI助手支持GPT4.0