formSubmit: function (event) {
var pics = this.data.pics;
console.log(pics);
var piccloud=[];
for (var i = 0; i<pics.length;i++){
var picid = Math.random();
console.log(picid)
var pic=pics[i];
console.log(pic);
wx.cloud.uploadFile({
cloudPath: picid+’.png’,
filePath: pic, // 小程序临时文件路径
success: res => {
piccloud.push(res.fileID)
console.log(piccloud)
// get resource ID
// picloud[i]=res.fileID
},
fail: err => {
}
})
console.log(piccloud);
}
》》》》》》为什么这后面的的代码,在wx.cloud.upload之前就执行了呢?
console.log(100)
var that=this;
var db=wx.cloud.database();
db.collection(‘test’).add({
data:{
title: event.detail.value.title,
content: event.detail.value.content,
photo: piccloud
},success:res=>{
console.log(100000)
wx.showToast({
title: ‘发布成功’, icon: ‘success’,
});
//发布成功后,返回首页,注意道js文件要…/返回到first页面
wx.reLaunch({
url: “…/first/first”,sucess:res=>{ }
})
}
})
},