收藏
回答

上拉加载更多触底时报错?

下拉加载触底时,调试器显示已经加载,页面没有加载出数据,并且报错,报错如图:

之前的10条信息调试器上没有显示时间,加载的信息有时间显示,如图:

代码如下:

//下拉刷新上啦加载
  loadrecruits:function(start=0){
    const that=this;
    let promise = db.collection("recruit");
    if(start > 0){
      promise = promise.skip(start);
    }
    promise.limit(10).orderBy("create_time","desc").get().then(res => {
      console.log(res);
      const recruits = res.data;
      let hasmore = true;
      if(recruits.length == 0){
        hasmore = false;
      }
      let newRecruits = [];
      if(start > 0){
        newRecruits = that.data.recruits.concat(recruits);
      }else{
        newRecruits = recruits;
      }
      newRecruits.forEach((recruit,index) => {
        recruit.create_time = recruit.create_time.getTime();
      })
      that.setData({
        recruits:newRecruits,
        hasmore:hasmore
      });
    })
  },
  onPullDownRefresh: function (event) {
    this.loadrecruits(0);
  },
  onReachBottom: function (event) {
    this.loadrecruits(this.data.recruits.length);
  },

我不知道下拉加载这个组件在wxml中位置是不是对的
wxml代码如下:
<wxs src="../../utils/util.wxs" module="util"/>


<searchbar isnavigator="{{true}}"></searchbar>
<import src="menu/menu.wxml" />
<view class="menu">
  <block wx:for="{{menus}}" wx:key="menu">
    <view catchtap="toHotPush" data-index="{{index}}">
      <template is="menu" data="{{...item}}"></template>
    </view>
  </block>
</view>


<view>
  <view class="ad-group">
    <image src="cloud://cloud1-9gsfk1on13e42e66.636c-cloud1-9gsfk1on13e42e66-1305874669/images/yingshiji.png"></image>
  </view>
</view>
<segment items="{{items}}" defaultIndex="0" bind:itemchanged="onSegmentItemChanged">
  <view slot="0" class="segment-page work-page">
    <view class="list-group" wx:for="{{recruits}}" wx:key="recruit" wx:for-item="recruit">
      <view class="list-title">自动化装配钳工</view>
      <view class="content">{{recruit.content}}</view>
      <view class="nickName">
        <image class="nickName-avatar" src="{{recruit.author.avatarUrl}}">
        </image>
        <view class="nickName-company">
          <view class="company">深圳市赢世纪科技有限公司</view>
          <view class="nickName-firstName">
            <view class="firstName">{{recruit.firstName}}</view>
            <!-- <view class="spot">·</view>
            <view class="position">人事经理</view> -->
          </view>
        </view>
        <button class="varchar">
          <image src="/images/telephone.png"></image>
          <text>电话</text>
        </button>
      </view>
      <view class="list-detail">
        <view class="detail-location">
          <image class="location" src="../../images/location.png"/>
          <text class="location-text">{{recruit.location.address}}</text>
        </view>
        <view class="detail-time">{{util.timeFormat(recruit.create_time)}}</view>
      </view>  
    </view>
    
  </view>
  
  <view slot="1" class="segment-page worker-page">
    <view class="worker-group">
      <view class="worker-top">
        <text></text>
      </view>
      <view class="worker">
        <view class="worker-left">
          <image src="cloud://cloud1-9gsfk1on13e42e66.636c-cloud1-9gsfk1on13e42e66-1305874669/images/pinche.jpg"></image>
        </view>
        <view class="worker-middle">
          <view class="top-list">
            <text class="name">张三</text>
            <text class="gender"></text>
            <text class="real-name">实名认证</text>
            
          </view>
          <view class="bottom-list">
            <text class="age">30岁</text>
            <text class="age-years">15年</text>
            <text class="education">中专</text>
            
          </view>
          <view class="worker-skill">
            <text class="skill">CAD</text>
            <text class="skill">SolidWorks</text>
          </view>
        </view>
        <view class="worker-right">
          <text class="topping">我要置顶</text>
          <text class="xz">个人</text>
        </view>
      </view>
      <view class="worker-introduce">
        <text>本人从事自动化设备10余年,熟练使用CAD,SW软件,对机械原理比较了解</text>
      </view>
      <viwe class="worker-expect">
        <text class="expect">期望</text>
        <view class="quyu">深圳</view>
        <view class="line">|</view>
        <view class="position">钳工</view>
        <view class="line">|</view>
        <view class="wages">5000-8000</view>
      </viwe>
    </view>
  </view>
  <view slot="2" class="segment-page carpooling-page">
    <view class="people-group">
  <view class="people-left">
    <view class="people-title">
      <view class="people-top">
        <text></text>
      </view>
      <view class="people-start">2021-11-25 09:36出发</view>
    </view>
    <view class="people-seat-list">
      <view class="people-model-title">车型:</view>
      <view class="people-model">七座商务车</view>
      <view class="people-seat">3空位</view>
    </view>
    <view class="people-route">
      <text class="people-rise">深圳石岩</text>
      <text class="people-arrow">→ </text>
      <text class="people-end">湖南省邵阳市洞口县</text>
      <text class="people-channel">(经东莞,广州,惠州,东莞长安 )</text>
    </view>
    <view class="people-details">
      <view class="people-remarks">备注:</view>
      <text>诚信拼车,行李少优先</text>
    </view>
  </view>
  <view class="people-right">
    <button class="people-contact">
      <image src="/images/telephone.png"></image>
    </button>
  </view>
</view>
  </view>
  <view slot="3" class="segment-page secondhand-page">二手交易的页面</view>
  <loadingmore hasmore="{{hasmore}}"></loadingmore>//下拉刷新上拉加载导入的组件
</segment>


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

1 个回答

  • dreamhunter
    dreamhunter
    2022-08-27
    recruit.create_time.getTime是什么?
    m没看到你代码里面有这个
    


    2022-08-27
    有用
    回复 2
    • 蓝天☁
      蓝天☁
      发表于移动端
      2022-08-27
      recruit是数据库集合名称,create_time 是插入到数据库中的时间,这两行是对时间格化中的time值转换,这个应该是上拉加载后的数据中的时间没有得到转换吧,但是代码中已经循环了
      2022-08-27
      回复
    • 蓝天☁
      蓝天☁
      2022-08-27
      newRecruits.forEach((recruit,index) => {
              recruit.create_time = recruit.create_time.getTime();
            }),这段代码是对时间对象的转换
      2022-08-27
      回复
登录 后发表内容