const app = getApp()
const db = wx.cloud.database()
let that = this
Page({
data: {
user_info:[],
queryResultname: '',
queryResultsex: '',
queryResultbirthday: '',
queryResultposition: '',
queryResultintro: '',
queryResulttel: '',
},
onLoad: function () {
wx.cloud.callFunction({
name: "getopenid",
success(res){
let _openid = res.result.openid
}
})
db.collection('user_info').where({
openid: this.data._openid
})
.get({
success: res => {
this.setData({
queryResultname: JSON.stringify(res.data[0].name, null, 0).replace("\"","").replace("\"",""),
queryResultsex: JSON.stringify(res.data[0].sex, null, 0).replace("\"","").replace("\"",""),
queryResultbirthday: JSON.stringify(res.data[0].birthday, null, 0).replace("\"","").replace("\"",""),
queryResultposition: JSON.stringify(res.data[0].position, null, 0).replace("\"","").replace("\"",""),
queryResultintro: JSON.stringify(res.data[0].intro, null, 0).replace("\"","").replace("\"",""),
queryResulttel: JSON.stringify(res.data[0].tel, null, 0).replace("\"","").replace("\"",""),
})
console.log('[数据库] [查询记录] 成功: ', res)
},
fail: err => {
wx.showToast({
icon: 'none',
title: '查询记录失败'
})
console.error('[数据库] [查询记录] 失败:', err)
}
})
},
使用 async/await
例如 const openid = await db.collection('user_info').get()
然后再把查询出来的openid用到下面的操作中。
另外数据库查询之外的代码怎么保证在数据出来后再执行?