收藏
回答

为何实现不了以下功能?

功能是:在加载这个页面的时候,当你已经认证过了,此处会变为

已认证。

相关功能代码:

wxml

<view class="subtitleid="shenfenbindtap="wrtusermsg">
        {{renzheng}}
            <!-- {{certificationOk == 2?"已认证":"未认证"}} -->
        </view>

n那个三元表达式我不清楚为何用不了,所以换了个变量。

js
data: {
        userInfo: null,
        certificationOk: null,
        avatarUrl: '',
    userInfo: {},
    logged: false,
    takeSession: false,
    requestResult: '',
    username:'',
    renzheng:"未认证"
    },
onload:function(options){
usermsg.where({
            upload:"1",
                    }).get({
                      success:function(res){
                        console.log(res);
                        this.setData({
                            renzheng:"已认证",
                            
                        })
                        console.log(certificationOk);
                      }
                    })//此处是用上传参数时的所附带的upload字段来判断是否已经认证(上传过数据了)
}
d但在此处数据库查询成功后该页面却仍然显示

回答关注问题邀请回答
收藏

2 个回答

  • 九歌^
    九歌^
    2020-05-27
    确定 this能找到嘛?certificationOk是否有赋值为2,工具栏是否有报错,能否贴下代码片段
    


    onload:(options){
      usermsg.where({
        upload:"1",
      }).get({
         success:function(res){
             console.log(res);
                this.setData({
                  renzheng:"已认证",
                })
                 console.log(certificationOk);
          }
      })//此处是用上传参数时的所附带的upload字段来判断是否已经认证(上传过数据了)
    }
    
    2020-05-27
    有用 1
    回复 4
    • Mr.Zhao
      Mr.Zhao
      2020-05-27
      我眼花了,竟然没看到,就是this.这个错误了
      2020-05-27
      回复
    • 九歌^
      九歌^
      2020-05-27回复Mr.Zhao
      嗯,因为 你是 function. this指向不对,你换成箭头函数就好了。
      2020-05-27
      回复
    • Hall of fame
      Hall of fame
      2020-05-28
      谢谢
      2020-05-28
      回复
    • 九歌^
      九歌^
      2020-05-28回复Hall of fame
      客气了。。。
      2020-05-28
      回复
  • Hall of fame
    Hall of fame
    2020-05-27
    var app = getApp()
    const db = wx.cloud.database();
    const usermsg = db.collection('usermsg');
    Page({
        data: {
            userInfonull,
            certificationOknull,
            avatarUrl'',
        userInfo: {},
        loggedfalse,
        takeSessionfalse,
        requestResult'',
        username:'',
        renzheng:"未认证"
        },
    
    
        onPullDownRefresh :function(){
            utils.getUserData();
            wx.stopPullDownRefresh()
        },
        
        onLoadfunction (options{
            var that = this;
            wx.getSetting({
                successres => {
                  if (res.authSetting['scope.userInfo']) {
                    // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
                    console.log("已经授权");
                    wx.getUserInfo({
                      successres => {
                        console.log(res);
                        this.setData({
                          avatarUrl: res.userInfo.avatarUrl,
                          userInfo: res.userInfo,
                          username:res.userInfo.nickName
                        })
                      }
                    })
                  }else{
                      console.log("未授权");
                  }
                }
              })
              usermsg.where({
                upload:"1",
                        }).get({
                          success:function(res){
                            console.log(res);
                            this.setData({
                                renzheng:"已认证".data,
                                
                            })
                            console.log(certificationOk);
                          }
                        })
            
        },
    b不清楚是否能找到,能找到应该也不至于赋值不上了,那个certification虽然没有赋值为2,但可以先不管,因为我用的是{{renzheng}}变量,相关代码已贴出
    
    2020-05-27
    有用
    回复
登录 后发表内容