在调用云函数时,出现VM221 WAService.js:2 TypeError: Cannot read property 'info1' of null的错误,根据错误位置发现是
wx.cloud.callFunction({
name: "love_getTie",
//一次加载5条数据,下拉加载更多
data:{
count:10,
page:0,
type:that.data.sid
},
success:res=>{
console.log("res",res);
//旧的数据加新获取数据的拼接
let oldData = that.data.message;
let newData = oldData.concat(res.result.info1.list);
//获取分类
...
这个调用函数中的info1,进行对云函数的测试发现传回的result为null,于是查看了云函数如下:
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
const db = cloud.database();
try{
let page = event.page;
let count = event.count;
let type = parseInt(event.type)
let info1,info2
if(type==0){
info1 = await db.collection("love_upload").aggregate().lookup({
from:'love_user',
localField: 'openid',
foreignField: 'openid',
as: 'result'
}).end();
info2 = await db.collection('love_sort').get()
}else{
info1 = await db.collection("love_upload").aggregate().lookup({
from:'love_user',
localField: 'openid',
foreignField: 'openid',
as: 'result'
}).end();
info2 = await db.collection('love_sort').get()
}
return {info1,info2}
}catch(e){
console.log(e);
}
}
查了一下,排除了网上所说的异步获取等等问题依旧没有排除出原因,希望有人帮我看看这代码是否有什么错误
看云函数日志