- Cannot read property 'length' of undefined?
调用云函数获取的数据库,为什么会显示这个错误?应该如何解决? js代码: Page({ data: { letters: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", contact: [], loc: "", screenHeight: 0, loginOK: false }, // 整理通讯录 arrangeContact: function () { wx.cloud.callFunction({ name:'contact', data:{ pageNum:1000, } }) .then(res => { console.log(res) var self = this; var contact = []; for (var i = 0; i < self.data.letters.length; i++) { var letter = self.data.letters[i]; var group = []; for (var j = 0; j < res.data.length; j++) { if (res.data[j].letter == letter) { group.push(res.data[j]); }; }; contact.push({ letter: letter, group: group }) }; self.setData({ contact: contact }); }) },
2021-12-17 - 发送订阅消息,放的是别人的openid,为什么会发送给我自己?
不管我放什么openid,放几个就发几遍给我自己是什么情况? sendMsg: function () { let users = [ "o6gY35UIf7", "o6gY35eNp" ] users.forEach(item => { console.log(item) wx.cloud.callFunction({ name: 'sendMsg', data: { openid: item, title: title, time: time, member: member, place: place, remarks: remarks }, success: res => { console.log(res) }, fail: err => { console.log(err) } }) }) 云函数代码: const cloud = require('wx-server-sdk') cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV, }) exports.main = async (event, context) => { const { OPENID } = cloud.getWXContext() try { const result = await cloud.openapi.subscribeMessage.send({ touser: event.openid, page: 'pages/index/index', templateId: "mv1AiOjD9ljPoaiFToRtIdZeW4T7uU8CTZLNBWdPNCQ", data: { thing1: { value: event.title }, time3: { value: event.time }, thing4: { value: event.member }, thing5: { value: event.place }, thing7: { value: event.remarks } } }) return result } catch (err) { console.log(err) return err } }
2021-12-16 - 发送订阅消息报erroCode:604100?
const cloud = require('wx-server-sdk') cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 云函数入口函数 exports.main = async (event, context) => { try { const result = await cloud.openapi.subscribeMessage.send({ touser: event.openid, page: 'pages/setting/setting', data: { thing1: { value: '' }, thing3: { value: '2021年12月10日 18:00~19:00' }, thing4: { value: '' }, thing5: { value: '' }, thing7: { value: '' } }, templateId: '', }) console.log(result) return result } catch (err) { console.log(err) return err } } 前端代码: getPermission:function(){ wx.requestSubscribeMessage({ tmplIds: ['mv1AiOjD9ljPoaiFToRtIdZeW4T7uU8CTZLNBWdPNCQ'], }) }, sendMsg:function(){ wx.cloud.callFunction({ name:"sendMsg", data:{ openid:"o6gY35eNuNk1p7k8Hc_VlOw8wKGI" } }).then(res=>{ console.log('发送成功',res) }) },
2021-12-10