收藏
回答

为什么console.log的数据不一致?

集合A的publisher字段存储了User集合的_id值,查询集合A记录的同时,通过存储在集合A的User的_id值获得User的username属性。

为什么上下两次打印的publisher值不一样?

const {result:{data}} = await wx.cloud.callFunction({
            name:'getAnimalList',
            data:{
                type:ID,
                pageIndex,
                pageSize
            }
        })
        data.forEach(item=>{
            db.collection('User').doc(item.publisher).get()
            .then(res=>{
                item.publisher = res.data.username
43               console.log(item.publisher)
            })
        })
46       console.log(data)
        this.setData({
            animalList:[...animalList, ...data]
        }) 
50       console.log(this.data.animalList)
51       console.log(this.data.animalList[0].publisher)


46行和50行打印的数据时一样的,publisher的值是User的username用户名小玉米,为什么51行打印的publisher又变成User的_id值了。

前端渲染不出用户名,求大佬救救

回答关注问题邀请回答
收藏

1 个回答

  • 横山火ya
    横山火ya
    04-24

    4个小时,终于。改用aggregate的lookup联表查询了。

    04-24
    有用
    回复
登录 后发表内容