创建两个发布页面,在写第二个发布页面时,再建了一个数据集合,因为都需要进行文字检测,我把插入数据库两个集合都写在一个云函数中,就提示报错如图:,再在第一个发布页面发布信息时,点击提交就没有反应
云函数代码:
if(errcode == 0){
if(collection==recruit){
return await db.collection("recruit").add({
data:{
content:content,
author:author,
location:location,
varchar:varchar,
firstName:firstName,
position:position,
work:work,
education:education,
create_time:db.serverDate(),
}
})
}else if(collection==release-resume){
return await db.collection("release-resume").add({
data:{
content:content,
author:author,
education:education,
full_Name:full_Name,
Gender:Gender,
Age:Age
}
})
}
}else{
return await {"errcode":1,"errmsg":"您的内容有风险,请修改再发布!"}
};
页面JS代码:
/**
* 发布事件
*/
onSubmitEvent:function(event){
console.log(event);
const content = event.detail.value.content;
const author=app.globalData.userInfo;
wx.showLoading({
title:"正在发表中..."
})
// 特3456书yuuo莞6543李zxcz蒜7782法fgnv级
wx.cloud.callFunction({
name:"recruit",
data:{
content:content,
author:author,
full_Name:event.detail.value.full_Name,
Gender:event.detail.value.Gender,
Age:event.detail.value.Age
},
success:res => {
console.log(res);
const _id = res.result._id;
if(_id){
wx.hideLoading();
wx.showToast({
title:"恭喜!发送成功!"
});
// setTimeout(function(){
// wx.navigateBack({})
// },800)
}else{
wx.showToast({
title:res.result.errMsg,
})
}
}
})
},
云函数结果返回打印出来,调试下