Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

我在data中定义一个num1数组,在getBarOption函数中获取数据库数据,想把这个数据赋值给num1,但是无法完成赋值。网上说是异步问题,我尝试了增加async和await,然后勾选“增强编译”,但是还是不行,报错说resCustomer.data中的data未定义。我用console.log(resCustomer)打印结果也是未定义,但是res是能获取到数据的。这是为什么?请问怎么解决这个问题呀?怎么才能赋值给num1呀?求大佬们指点一二。

data: {
    num1:[],
},
async function  getBarOption() {
  const db = wx.cloud.database()
  let that=this;

  let resCustomer= await db.collection('user').where({
      _openid:getApp().globalData.openid
   }).get({
       success: res => {
           console.log('查到的值为', res)
        }
      })

  that.setData({
     num1:resCustomer.data
  })
  console.log("resCustomer:"+resCustomer);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
744 views
Welcome To Ask or Share your Answers For Others

1 Answer

想了好久还是没思路,求大佬们给点意见。感谢


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...