- 在onLoad中用setdata设置不成功?
代码如下: const db = wx.cloud.database() Page({ data: { banner: [] }, onLoad: function () { let that = this db.collection('swiper').get({ success: function (res) { console.log('轮播图获取成功111', res) that.setdata({ banner: res.data }) console.log('轮播图获取成功222', res) }, fail: function (res) { console.log('轮播图获取失败', res) }, }) } }); 控制台输出如下: 轮播图获取成功111 {data: Array(3), errMsg: "collection.get:ok"} VM5313:3 Thu Oct 19 2023 12:05:49 GMT+0800 (中国标准时间) 云开发数据库索引建议 VM5313:4 发起的如下数据库查询经自动检测发现以下问题 (anonymous) @ VM5313:4 (anonymous) @ VM5313:11 VM5313:5 查询语句: VM5313:6 db.collection('swiper').where({}) .get() VM5313:8 1. 全量查询告警: 空查询语句可能需扫全表 (anonymous) @ VM5313:8 (anonymous) @ VM5313:11 无法正常给that赋值,第一次读取数据库信息能打印,第二次无法打印。 [图片] 怎么才能正确赋值,并第二次能正常打印呢?
2023-10-19 - 云开发调用集合报错:501009 resource not initialized ?
代码如下: { const db = wx.cloud.database() Page({ data: { }, onLoad: function () { db.collection('aaaaa').get({ success: function (res) { console.log('轮播图获取成功', res) }, fail: function (res) { console.log('轮播图获取失败', res) }, }) } }); } [图片] [图片] 具体报错信息如下: 轮播图获取失败 Error: errCode: -501009 resource not initialized | errMsg: Please initialize the reource first at new t (WASubContext.js?t=wechat&s=1697378812673&v=2.14.1:17) at Function.success (WASubContext.js?t=wechat&s=1697378812673&v=2.14.1:17) at f (WASubContext.js?t=wechat&s=1697378812673&v=2.14.1:2) at Object.success (WASubContext.js?t=wechat&s=1697378812673&v=2.14.1:2) at r (WASubContext.js?t=wechat&s=1697378812673&v=2.14.1:26) at WASubContext.js?t=wechat&s=1697378812673&v=2.14.1:26 at b (WASubContext.js?t=wechat&s=1697378812673&v=2.14.1:26) at WASubContext.js?t=wechat&s=1697378812673&v=2.14.1:26 at WAServiceMainContext.js:11 at VM9 asdebug.js:1 简单的创建的集合,按照教程进行云数据库调用,环境变量应该是默认的(没搞明白怎么设置,直接默认的)。现在出现这个-501009报错,求解决方案0.0.
2023-10-15