- 云函数保存数据到excel报错?TypeError: Cannot read property '0
之前有另一个云函数整理数据库的文件,已打印验证之前那个云函数没问题,大概1300行10列左右的数据 现在这个excel云函数用来读然后存到excel里, 之后要上传到云存储 问题就是出现在excel云函数读完数据存不下来, 但不知道是数 报错: 11/08 23:00:07:821 [excel][1] ERROR RequestId: b5df872c-7e96-43f3-8b15-30a6078d380f Result: TypeError: Cannot read property '0' of undefined at exports.main (/var/user/index.js:39:49) at IncomingMessage.<anonymous> (/data/scf/frame/node12/runtime.js:246:26) at IncomingMessage.emit (events.js:323:22) at endReadableNT (_stream_readable.js:1204:12) at processTicksAndRejections (internal/process/task_queues.js:84:21) excel云函数代码: // 云函数入口文件 const cloud = require('wx-server-sdk') const moment = require("moment-timezone") cloud.init({ traceUser: true, env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境 //操作excel用的类库 const xlsx = require('xlsx'); // 云函数入口函数 exports.main = async(event, context) => { let {userdata} = event // javascript date // console.log(new Date()); // 2021-03-16T08:04:07.441Z (UTC+0 // console.log(moment().tz("Asia/Shanghai").format()); // 2021-03-16T16:04:07+08:00 (UTC+8) let curDate = moment().tz("Asia/Shanghai").format('YYYYMMDDHHmmss'); //let curDate =new Date().toISOString() //1,定义excel表格名 let dataCVS = 'xiaofu101_order_list_'+curDate+'.xlsx' //2,定义存储数据的 let alldata = []; //let row = ['status','receiver']; //表属性 let row=['_id' , 'orderDate', 'region','address','receiver','phone' ,'SchoolName','cloth_id','cloth_notes','num','cloth_price','totalPrice','status'] alldata.push(row); console.log('excel before loop:'+alldata) let count = 0 for (let key in userdata) { for (let i in userdata[key]['product']){ let arr = []; arr.push(userdata[key]._id); arr.push(userdata[key].orderDate); arr.push(userdata[key]['address'].region[0]+'-' +userdata[key]['address'].region[1]+'-' +userdata[key]['address'].region[2]); arr.push(userdata[key]['address'].address); arr.push(userdata[key]['address'].receiver); arr.push(userdata[key]['address'].phone); arr.push(userdata[key].curSchoolName); arr.push(userdata[key]['product'][i].cloth_id); arr.push(userdata[key]['product'][i].cloth_notes); arr.push(userdata[key]['product'][i].cloth_price); arr.push(userdata[key]['product'][i].num); arr.push(userdata[key].totalPrice); arr.push(userdata[key].status); alldata.push(arr) } count += 1 console.log(count) } console.log('excel has data:'+alldata) //3,把数据保存到excel里 const buffer = xlsx.utils.book_new(); const worksheet = xlsx.utils.aoa_to_sheet(alldata); xlsx.utils.book_append_sheet(buffer, worksheet, 'mySheetName'); const excelBuffer = xlsx.write(buffer, { type: 'buffer' }); console.log('buffer has data : ', excelBuffer); //4,把excel文件保存到云存储里 console.log(dataCVS) return await cloud.uploadFile({ cloudPath: dataCVS, fileContent: excelBuffer, //excel二进制文件 }) } 这条语句没有执行打印出来, console.log('excel has data:'+alldata) console.log(count)打印出来了 说明错可能是在上面 alldata.push(arr) 但不知道是保存的数据类型造成的property '0' of undefined还是怎么回事, 请问怎么同时调式2个云函数,现在只能调式1个excel云函数,不能模拟传数据库数据的情况
11-08 - 小程序 微信支付失败 查了下是订单详情长度越界 这个怎么办?
//把商品信息写进body var good_info=''; for(let i=0;i<cart.length;i++){ good_info+=cart[i].cloth_title+';'; } console.log(good_info) var good_details=''; for(let j=0;j<cart.length;j++){ good_details+=cart[j].cloth_id+' x '+cart[j].num+';'; } console.log(good_details); const body = good_info;//订单名称 const details = good_details;//订单详情 const inputSubmitVal = totalPrice * 100;//系统是用分开始计算 console.log(totalPrice); if (totalPrice>0) { const res=await showModal({content:"您确定要提交订单了吗?。"}); if (res.confirm) { //提交订单 this._callQuestionPay(body, details,goodsnum, subMchId, inputSubmitVal ); //if not wepay, use this.creatOrder(goodsnum); } } else { await showToast({title:"亲,没有商品,无法提交哦"}); } // 请求questionPay云函数,调用支付能力 _callQuestionPay(body, details,goodsnum, subMchId, payVal) { wx.cloud .callFunction({ name: 'questionPay', data: { // 需要将data里面的参数传给questionPay云函数 body, details, goodsnum, // 商品订单号不能重复 subMchId, // 子商户号,微信支付商户号,必填 payVal, // 这里必须整数,不能是小数,而且类型是number,否则就会报错 nonceStr:uuid(32, 32)//调用自己的uuid函数 不用也行 原来发现错在totalprice没值 }, }) .then((res) => { console.log(res);//商户支付受限 const payment = res.result.payment; console.log('payment:'+payment); // 里面包含appId,nonceStr,package,paySign,signType,timeStamp这些支付参数 wx.requestPayment({ // 根据获取到的参数调用支付 API 发起支付 ...payment, // 解构参数appId,nonceStr,package,paySign,signType,timeStamp success: (res) => { console.log('支付成功', res); wx.showToast({ title: '支付成功', success: () => console.log('success'), fail: () => console.log('failure'), }); this.creatOrder(goodsnum); }, fail: (err) => { console.error('支付失败', err); wx.showToast({ title: '支付失败', success: () => console.log('success'), fail: () => console.log('failure'), }); }, }); }) .catch((err) => { console.error(err); }); }, [图片] 貌似是这个details越界了 这个怎么能限制一下?
2023-10-19 - 请问云开发导出数据库失败 怎么办?
[图片] 这是什么原因 是因为是国外ip吗? 那人在国外维护国内小程序 那怎么才能导出?
2022-09-07 - 2年没用 push failed 远程推送github失败?同时开发工具更新出错无法更新
[图片] 2年没登了 远程push github 出问题,已经检查了 设置->网络和认证里的用户名密码是对的 [图片] 难道是版本问题?现在还有个问题开发工具下载的更新无法安装 [图片]
2022-09-06 - openSetting()的问题,我用了打不开设置?
关于为了避免用户取消“获取地址”之后无法再打开,我看教程说是用opensetting(). https://www.bilibili.com/video/BV1y7411z7hQ?p=85 但是代码一样还是没用。我用openSetting()怎么还打不开设置,不知道哪错了. 点取消授权,再点button, console确实输出我故意打印的“取消”了但并没有打开设置。 WXML: 获取收货地址 JS. handleChooseAddress(){ wx.getSetting({ success: (result) => { // console.log(result); const scopeAddress=result.authSetting["scope.address"]; if (scopeAddress===true||scopeAddress===undefined){ //console.log(result); wx.chooseAddress({ success: (result1) => { console.log(result1); } }); }else{ console.log("取消"); wx.openSetting({ success: (result2) => { wx.chooseAddress({ success: (result3) => { console.log(result3); } }); } }); } } }) } 另一种写法还是不对 : 报错:errMsg: "openSetting:fail errcode 1"} /* Promise形式 getSetting */ export const getSetting=()=>{ return new Promise((resolve,reject)=>{ wx.getSetting({ withSubscriptions: true, success: (result)=>{ resolve(result); }, fail:(err)=>{ reject(err); } }); }) } /* Promise形式 chooseAddress */ export const chooseAddress=()=>{ return new Promise((resolve,reject)=>{ wx.chooseAddress({ withSubscriptions: true, success: (result)=>{ resolve(result); }, fail:(err)=>{ reject(err); } }); }) } /* Promise形式 openSetting */ export const openSetting=()=>{ return new Promise((resolve,reject)=>{ wx.openSetting({ withSubscriptions: true, success: (result)=>{ resolve(result); }, fail:(err)=>{ reject(err); } }); }) } // pages/cart/index.js import{getSetting,chooseAddress,openSetting } from "../../utils/asyncWx.js"; import regeneratorRuntime from '../../lib/runtime/runtime'; Page({ /** * 页面的初始数据 */ data: { }, async handleChooseAddress(){ try { /* wx.getSetting({ success: (result) => { // console.log(result); const scopeAddress=result.authSetting["scope.address"]; if (scopeAddress===true||scopeAddress===undefined){ //console.log(result); wx.chooseAddress({ success: (result1) => { console.log(result1); } }); }else{ console.log("取消"); wx.openSetting({ success: (result2) => { wx.chooseAddress({ success: (result3) => { console.log(result3); } }); } }); } }, fail:()=>{}, complete:()=>{} }); */ const res1=await getSetting(); const scopeAddress=res1.authSetting["scope.address"]; if (scopeAddress===false){ await openSetting(); } const res2=await chooseAddress(); console.log(res2); } catch (error) { console.log(error); } } })
2020-07-27