// 云函数入口文件 const cloud = require('wx-server-sdk') cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) const db = cloud.database() const _ = db.command // 云函数入口函数 exports.main = async (event, context) => { console.log(event) let ps const usersID = event.usersID; let res = await db.collection('usersdatas').where({_id: usersID}).get() const threepartysid = res.data.threepartysid let allid = await db.collection('usersinternet').where({_id: _.in(threepartysid) }).limit(1000).get() //const allid = reslist.data const newOpenid = []; for (let i = 0; i < allid.length; i++) { if (allid[i].isEnable === true) { newOpenid.push(allid[i]); } } const productOpenid = newOpenid.map(item => ( item.threepartyid )); const newCloseid = []; for (let i = 0; i < allid.length; i++) { if (allid[i].isGroupMember === false || allid[i].closedate < getToday() ) { newCloseid.push(allid[i]); } } const closeopenid = newCloseid.map(item => ( item.threepartyid )); const ps = [productOpenid,closeopenid] return ps }指出代码中的问题,并修复问题,把正确的代码发给我
时间: 2023-11-28 08:47:47 浏览: 82
在代码中,变量 `ps` 被定义了两次,第一次是声明变量,第二次是赋值变量。同时,在循环中,变量 `allid` 是一个对象数组,而不是单个对象。因此,需要修改代码如下:
```javascript
const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database()
const _ = db.command
exports.main = async (event, context) => {
console.log(event)
const usersID = event.usersID;
let res = await db.collection('usersdatas').where({_id: usersID}).get()
const threepartysid = res.data[0].threepartysid // data 是一个数组,取第一个元素的 threepartysid
let allid = await db.collection('usersinternet').where({_id: _.in(threepartysid) }).limit(1000).get()
const newOpenid = [];
const newCloseid = [];
for (let i = 0; i < allid.data.length; i++) { // allid 是一个对象,取 data 属性
if (allid.data[i].isEnable === true) {
newOpenid.push(allid.data[i]);
}
if (allid.data[i].isGroupMember === false || allid.data[i].closedate < getToday() ) {
newCloseid.push(allid.data[i]);
}
}
const productOpenid = newOpenid.map(item => (
item.threepartyid
));
const closeopenid = newCloseid.map(item => (
item.threepartyid
));
return [productOpenid,closeopenid]; // 返回数组
}
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)