云开发 关联查询数据?
发布于 6 年前 作者 gongfang 5735 次浏览 来自 官方Issues

我查询我的收藏 记录  然后想关联查询出我的收藏数据

/**
  * 获取我的收藏记录
  */
  get_collection: function () {
    const db = wx.cloud.database()
    const _ = db.command
    var openid = wx.getStorageSync('openid')
    //先获取收藏记录数据
    db.collection('collection').where({
      _openid: openid
    }).get({
      success(res){
        var date = res.data;
        var id = [];
        for (var i = 0; i<date.length;i++){
          id[i] = date[i].id;
        }
        //获得处理为数组 id=【25,26】
       // 再通过数组查询相关ID的数据
        db.collection('content').where({
          _id: _.in(id)
        }).get({
          success(res){
            // this.setData({
            //   date_arry: res.data
            // })
            console.log(res);
          },fail(res){
 
          }
        })
         
      },
      fail(res){ console.log(res) }
    })
  }

在第二步通过数组ID查询数据 为什么set不成功 还有就是有时候能查询的到 有事查询不到数据记录  就是下面这个代码 的success方法

// 再通过数组查询相关ID的数据
        db.collection('content').where({
          _id: _.in(id)
        }).get({
          success(res){
            // this.setData({
            //   date_arry: res.data
            // })
            console.log(res);
          },fail(res){
  
          }
        })
回到顶部