收藏
回答

数据库分类查询,console.log()出了的结果是0?

数据库中的carpool_tppe:"我要找车",是发布信息界面选择的发布信息类型,想以这个类型对数据进行分类,显示在导航栏对应的数据中,console.log()打印出来的结果是0,没有获取到数据,如图:

wxml代码:

<segment items="{{items}}" defaultIndex="0"
binditemchanged="onSegmentItemChanged" >
  <view slot="0" class="segment-page people">
    <view class="quanbu-group">
      <view class="shu-group">|</view>
      <text>全部信息(共有500条信息)</text>
      <view class="paixu-group">按出发时间排序</view>
    </view>
    <view class="people-group" wx:for="{{carpoolings}}" wx:key="key" wx:for-item="carpooling">
      <view class="people-left">
        <view class="people-title">
          <view class="people-top">
            <text></text>
          </view>
          <view class="departure-time">出发:</view>
          <view class="people-start">{{carpooling.date}}</view>
        </view>
        <view class="people-route">
          <text class="people-content">{{carpooling.departure_address}}</text>
          <text class="people-arrow">→ </text>
          <text class="purpose-content">{{carpooling.end}}</text>
          <text></text>
          <text class="channel-centent">{{carpooling.channel}}</text>
          <text></text>
        </view>
        <view class="people-seat-list">
          <view class="people-model-title">车型:</view>
          <view class="people-model">{{carpooling.vehicle_type}}</view>
          <view class="people-seat">{{carpooling.people}}空位</view>
        </view>
        <view class="people-details">
          <view class="people-remarks">备注:</view>
          <text>{{carpooling.content}}</text>
        </view>
        <view class="release-list">
          <view class="release">发布:</view>
          <view class="detail-time">2022/9/2 8:35:36</view>
        </view>
      </view>
      <view class="people-right">
        <button class="people-contact">
          <image src="/images/telephone.png"></image>
        </button>
      </view>
    </view>
  </view>
  <view slot="1" class="segment-page car"></view>
</segment>
js代码:
 onLoadfunction (options{
 
  },
  loadcarpoolings:function(){
    const that=this;
    
    db.collection("carpooling").where({
    
     carpool_type:"我要找车"
    }).limit(10).get().then(res=>{
      console.log(res);
      const carpoolings = res.data
      that.setData({
        "carpoolings":carpoolings
      })
    })
  
  },
  onSegmentItemChanged:function(event){
    // console.log(event);
    const active = event.detail.index;
    this.setData({
      active:active
    })
  
    console.log(event.detail.index);
    db.collection("carpooling").where({
      carpool_type:event.detail.index.toString()
    })
    .get({
      success:function(res){
        console.log(res);
        that.setData({
          "carpooling":res.data
        })
      }
    })
  
  },
回答关注问题邀请回答
收藏

1 个回答

  • Yuan
    Yuan
    2022-09-07

    看下network里这个请求有返回参数没

    2022-09-07
    有用
    回复 5
    • 蓝天☁
      蓝天☁
      2022-09-07
      2022-09-07
      回复
    • Yuan
      Yuan
      2022-09-14回复蓝天☁
      那这就是接口返回参数的问题呀,array(0)就意思没数组,数组空的
      2022-09-14
      回复
    • 蓝天☁
      蓝天☁
      2022-09-14
      接口要怎么弄?
      2022-09-14
      回复
    • 吉利娘子军家政-社保-证件
      吉利娘子军家政-社保-证件
      2023-02-08回复蓝天☁
      db.collection前面加 await, 形如:await db.collection("carpooling“),因为云函数在处理数据库采用的是异步方式
      2023-02-08
      回复
    • 蓝天☁
      蓝天☁
      2023-05-09
      谢谢
      2023-05-09
      回复
登录 后发表内容