想实现同步,getData调用getathead,getathead又调用gethead,但出现promise未定义的报错,请问正确该怎么写
onLoad: function (options) {
this.getData();
},
async getData(){
var that= this
var id = wx.getStorageSync('info').id
db.collection('Notice')
.where({
message:"@",
noticed:id
}).get()
.then(res=>{
that.setData({
atlist:res.data
})
that.getathead();
})
},
async getathead(){
var p = this.data.atlist;
return new promise((reslove,reject)=>{
for(let i =0;i<p.length;i++)
{
this.gethead(p.uid);
}
reslove()
})
},
gethead(id){
var list=this.data.headlist;
return new promise((reslove,reject)=>{
db.collection('Student')
.where({
_id:id
}).get()
.then(res=>{
if(res.data.length==0)
{
db.collection('Teacher')
.where({
_id:id
}).get()
.then(res=>{
list.push(res.data[0].pic)
this.setData({
headlist:list,
})
reslove()
})
}
else
{
list.push(res.data[0].pic)
this.setData({
headlist:list,
})
reslove()
}
})
})
},
promise是首字母大写