收藏
回答

在onload里面写查数据库,查询结果却在onready之后,求大佬讲解一下

框架类型 问题类型 终端类型 AppID 基础库版本
小程序 Bug 客户端 wx52213d3cefee9913 2.2.5

如下图所示,在onload里写的查数据库的方法,却在onready之后打印出结果

具体方法如下:

  onLoad:function(options){

    this.searchInfo()

  },

searchInfo:function(){

    console.log("onshow....")

    const db = wx.cloud.database()

    console.log("onshow111")

    db.collection('problem').where({

      _openid: this.data.openid,

    }).get({

      success: res => {

        this.setData({

          items: JSON.stringify(res.data, null, 2)

        })

        console.log("123:", this.data.items)

      },

      fail: err => {

        wx.showToast({

          icon: 'none',

          title: '查询记录失败'

        })

      }

    })

  }



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

1 个回答

  • 半寸灰
    半寸灰
    2018-09-30

    查询结果异步操作  需要一定的时间的


    2018-09-30
    有用
    回复
登录 后发表内容