收藏
回答

当只有一条或者没有数据的情况时,一直显示正在加载中?

当只有一条或者没有数据的情况下,一直显示正在加载中,如果全部项下拉加载出数据后,才会显示没有更多如图1。再就是当下拉加载时,第二次下拉时显示的没有更多数据,而不是显示正在加载中如图2。好像是和其他项有冲突。这个问题怎么解决?

图片:

代码:

<!--components/loadingmore/loadingmore.wxml-->
<button class="loading-btn" loading="{{hasmore}}" style="height:{{height}}px;">
  <block wx:if="{{hasmore}}">
    <text class="loadingtext">{{loadingtext}}</text>
  </block>
  <block wx:else>
    <text class="loadingtext">{{loadedtext}}</text>
  </block>
</button>

index.wxml代码:

<segment-carpool items="{{items}}" result="{{result}}" resultthree="{{result3}}" resultfous="{{result4}}"   binditemchengde="onItemChengdeEvent" defaultIndex="0" >
  <view slot="0" class="segment-page wehicle-page">
    <view class="comment-title">全部信息(共有{{result}}条)</view>
    <whole wx:for="{{wehicles}}" wx:key="wehicle" wx:for-item="wehicle" wehicle="{{wehicle}}"></whole>
  </view>
  <view slot="1" class="segment-page people-page">
    <view class="comment-title">全部信息(共有{{result1}}条)</view>
    <wehicle wx:for="{{listones}}" wx:key="key" wx:for-item="listone" list1="{{listone}}"></wehicle>
  </view>
  <view slot="2" class="segment-page train-page">
    <view class="comment-title">全部信息(共有{{result2}}条)</view>
    <people wx:if="{{listtwos}}" wx:for="{{listtwos}}" wx:key="key" wx:for-item="listtwo" list2="{{listtwo}}"></people>
  </view>
  <view slot="3" class="segment-page money-page">
    <view class="comment-title">全部信息(共有{{result3}}条)</view>
    <train wx:for="{{listthrees}}" wx:key="key" wx:for-item="listthree" list3="{{listthree}}"></train>
  </view>
  <view slot="4" class="segment-page money-page" >
    <view class="comment-title">全部信息(共有{{result4}}条)</view>
    <money wx:for="{{listfours}}" wx:key="key" wx:for-item="listfour" list4="{{listfour}}"></money>
  </view>
</segment-carpool> 
<loadingmore hasmore="{{hasmore}}"></loadingmore>

index.jd代码:

const db = wx.cloud.database();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    items: ["全部""我要找车""我要找人""我找货车""我要找货"],
    hasmore: true,
    wehicles: [],
    result: 0,
    result1: 0,
    result2: 0,
    result3: 0,
    result4: 0,
    startPoint:'',
    goal: '',
    isQuerying: false,
    list:[],
    listones:[],
    listtwos:[],
    listthrees:[],
    listfours:[],
  },

  /**
   * 获取起点输入信息
   */
  onStartPointEvent(event) {
    const that = this;
    const startPoint = event.detail.value
    console.log('起点', startPoint);
    that.setData({
      startPoint: startPoint
    })
  },
  /**
   * 获取终点输入信息
   */
  onGoalEvent(event) {
    const that = this;
    const goal = event.detail.value
    console.log('终点', goal);
    that.setData({
      goal: goal
    })
  },


  /**
   * 按条件查询数据
   */
  formSubmit(event) {
    console.log(event);
    const that = this;
    that.setData({
      isQuerying: true
    })
     let list = db.collection("wehicle").where({
      startPoint: that.data.startPoint,
      goal: that.data.goal,
    });
    if (event > 0) {
    list = list.skip(event);
    }
    list.limit(5).orderBy("create_time""desc").get().then(res => {
    console.log(res);
    const wehicles = res.data;
    let hasmore = true
    if (wehicles.length == 0) {
      hasmore = false
    }
    let newWehicles = [];
    if (event > 0) {
      newWehicles = that.data.wehicles.concat(wehicles);
    } else {
      newWehicles = wehicles;
    }
    newWehicles.forEach((wehicle, index) => {
      wehicle.create_time = wehicle.create_time.toString();
    })
    that.setData({
      wehicles: newWehicles,
      hasmore: hasmore,
    })
    });
    list.count().then(res => {
      console.log(res)
      that.setData({
        result:res.total
      })
    })
    let list1 = db.collection("wehicle").where({
      startPoint: that.data.startPoint,
      goal: that.data.goal,
      carpool:'我要找车'
    });
      if (event > 0) {
        list1 = list1.skip(event);
      }
      list1.limit(5).orderBy("create_time""desc").get().then(res => {
        const listones = res.data;
        let hasmore = true
        if (listones.length == 0) {
          hasmore = false
        }
        let newones = [];
        if (event > 0) {
          newones = that.data.listones.concat(listones);
        } else {
          newones = listones;
        }
        newones.forEach((wehicle, index) => {
          wehicle.create_time = wehicle.create_time.toString();
        })
        that.setData({
          listones: newones,
          hasmore: hasmore,
        })
      });
    list1.count().then(res => {
      console.log(res)
      that.setData({
        result1:res.total
      })
    })


    let list2 = db.collection("wehicle").where({
      startPoint: that.data.startPoint,
      goal: that.data.goal,
      carpool:'我要找人'
    });
    if (event > 0) {
      list2 = list2.skip(event);
    }
    list2.limit(5).orderBy("create_time""desc").get().then(res => {
        console.log(res);
      const listtwos = res.data;
      let hasmore = true
      // let hasmore = listtwos.length > 0;
      if (listtwos.length == 0) {
        hasmore = false
      }
      let newtwos = [];
      if (event > 0) {
        newtwos = that.data.listtwos.concat(listtwos);
      } else {
        newtwos = listtwos;
      }
      newtwos.forEach((wehicle, index) => {
        wehicle.create_time = wehicle.create_time.toString();
      })
      that.setData({
        listtwos: newtwos,
        hasmore: hasmore,
      })
    });
      list2.count().then(res => {
        console.log(res)
        that.setData({
          result2:res.total
        })
      })
      let list3 = db.collection("wehicle").where({
        startPoint: that.data.startPoint,
        goal: that.data.goal,
        carpool:'我找货车'
      });
      if (event > 0) {
        list3 = list3.skip(event);
      }
      list3.limit(5).orderBy("create_time""desc").get().then(res => {
          console.log(res);
        const listthrees = res.data;
        let hasmore = true
        // let hasmore = listthrees.length > 0;
        if (listthrees.length == 0) {
          hasmore = false
        }
        let newthrees = [];
        if (event > 0) {
          newthrees = that.data.listthrees.concat(listthrees);
        } else {
          newthrees = listthrees;
        }
        newthrees.forEach((wehicle, index) => {
          wehicle.create_time = wehicle.create_time.toString();
        })
        that.setData({
          listthrees: newthrees,
          hasmore: hasmore,
        })
      });
      list3.count().then(res => {
        console.log(res)
        that.setData({
          result3:res.total
        })
      })
      let list4 = db.collection("wehicle").where({
        startPoint: that.data.startPoint,
        goal: that.data.goal,
        carpool:'我要找货'
      });
      if (event > 0) {
        list4 = list4.skip(event);
      }
      list4.limit(5).orderBy("create_time""desc").get().then(res => {
          console.log(res);
        const listfours = res.data;
        let hasmore = true
        // let hasmore = listfours.length > 0;
        if (listfours.length == 0) {
          hasmore = false
        }
        let newfours = [];
        if (event > 0) {
          newfours = that.data.listfours.concat(listfours);
        } else {
          newfours = listfours;
        }
        newfours.forEach((wehicle, index) => {
          wehicle.create_time = wehicle.create_time.toString();
        })
        that.setData({
          listfours: newfours,
          hasmore: hasmore,
        })
      });
    list4.count().then(res => {
        console.log(res)
        that.setData({
          result4:res.total
        })
      })
    // that.updateCount(index);
    that.setData({
      startPoint:'',
      goal:'',
    })
  }, 
  /**
   * 获取选项卡计数
   */
  onItemChengdeEvent(event) {
    const that = this;
    var index = event.detail.index;
  },
  /**
   * 获取数据库数据
   */
  lowdrelease(start = 0) {
    const that = this;
    let list = db.collection("wehicle");
      if (start > 0) {
        list = list.skip(start);
      }
      list.limit(5).orderBy("create_time""desc").get().then(res => {
          console.log(res);
        const wehicles = res.data;
        let hasmore = true
        if (wehicles.length == 0) {
          hasmore = false
        }
        let newWehicles = [];
        if (start > 0) {
          newWehicles = that.data.wehicles.concat(wehicles);
        } else {
          newWehicles = wehicles;
        }
        newWehicles.forEach((wehicle, index) => {
          wehicle.create_time = wehicle.create_time.toString();
        })
        that.setData({
          wehicles: newWehicles,
          hasmore: hasmore,
        })
      });
  
        list.count().then(res => {
          console.log(res)
          that.setData({
            result:res.total
          })
        })
      
      let list1 = db.collection("wehicle").where({carpool:'我要找车'});
      if (start > 0) {
        list1 = list1.skip(start);
      }
      list1.limit(5).orderBy("create_time""desc").get().then(res => {
          console.log(res);
        const listones = res.data;
        let hasmore = true
        if (listones.length == 0) {
          hasmore = false
        }
        let newones = [];
        if (start > 0) {
          newones = that.data.listones.concat(listones);
        } else {
          newones = listones;
        }
        newones.forEach((wehicle, index) => {
          wehicle.create_time = wehicle.create_time.toString();
        })
        that.setData({
          listones: newones,
          hasmore: hasmore,
        })
      });


        list1.count().then(res => {
          console.log(res)
          that.setData({
            result1:res.total
          })
        })
      let list2 = db.collection("wehicle").where({carpool:'我要找人'});
      if (start > 0) {
        list2 = list2.skip(start);
      }
      list2.limit(5).orderBy("create_time""desc").get().then(res => {
          console.log(res);
        const listtwos = res.data;
        let hasmore = true
        if (listtwos.length == 0) {
          hasmore = false
        }
        let newtwos = [];
        if (start > 0) {
          newtwos = that.data.listtwos.concat(listtwos);
        } else {
          newtwos = listtwos;
        }
        newtwos.forEach((wehicle, index) => {
          wehicle.create_time = wehicle.create_time.toString();
        })
        that.setData({
          listtwos: newtwos,
          hasmore: hasmore,
        })
      });
        list2.count().then(res => {
        console.log(res)
        that.setData({
          result2:res.total
        })
      })
     
      let list3 = db.collection("wehicle").where({carpool:'我找货车'});
      if (start > 0) {
        list3 = list3.skip(start);
      }
      list3.limit(5).orderBy("create_time""desc").get().then(res => {
          console.log(res);
        const listthrees = res.data;
        let hasmore = true
        // let hasmore = listthrees.length > 0;
        if (listthrees.length == 0) {
          hasmore = false
        }
        let newthrees = [];
        if (start > 0) {
          newthrees = that.data.listthrees.concat(listthrees);
        } else {
          newthrees = listthrees;
        }
        newthrees.forEach((wehicle, index) => {
          wehicle.create_time = wehicle.create_time.toString();
        })
        that.setData({
          listthrees: newthrees,
          hasmore: hasmore,
        })
      });
        list3.count().then(res => {
        console.log(res)
        that.setData({
          result3:res.total
        })
      })
      
      let list4 = db.collection("wehicle").where({carpool:'我要找货'});
      if (start > 0) {
        list4 = list4.skip(start);
      }
      list4.limit(5).orderBy("create_time""desc").get().then(res => {
          console.log(res);
        const listfours = res.data;
        let hasmore = true
        // let hasmore = listfours.length > 0;
        if (listfours.length == 0) {
          hasmore = false
        }
        let newfours = [];
        if (start > 0) {
          newfours = that.data.listfours.concat(listfours);
        } else {
          newfours = listfours;
        }
        newfours.forEach((wehicle, index) => {
          wehicle.create_time = wehicle.create_time.toString();
        })
        that.setData({
          listfours: newfours,
          hasmore: hasmore,
        })
      }); 
        list4.count().then(res => {
        console.log(res)
        that.setData({
          result4:res.total
        })
      })    
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.lowdrelease(0);
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.lowdrelease(0);
    this.setData({
      isQuerying:false
    }) 
    wx.stopPullDownRefresh();
  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
      if(!this.data.isQuerying) {
        this.lowdrelease(this.data.wehicles.length);   
      }else{
        this.data.isQuerying
      }  
  },
})
回答关注问题邀请回答
收藏

1 个回答

  • 小黎
    小黎
    08-06

    只查询当前tab页的数据啊,你的方法里面所有tab页的查询都执行了

    08-06
    有用
    回复 6
    • 蓝天☁
      蓝天☁
      08-06
      那这个一直显示正在加载中是什么情况呢?其它几个项就只有一条数据,或者没有数据,就一直显示正在加载中,除非上拉把所有的数据都加载出来了才会显示没有更多
      08-06
      回复
    • 小黎
      小黎
      08-06回复蓝天☁
      默认显示暂无数据,上拉加载的时候显示加载中,有下一页数据才显示上拉加载
      08-06
      回复
    • 蓝天☁
      蓝天☁
      08-06回复小黎
      data: {
          hasmore: false,
      }
      list.limit(5).orderBy("create_time", "desc").get().then(res => {
                console.log(res);
              const wehicles = res.data;
              let hasmore = false
              if (wehicles.length > 5) {
                hasmore = true
              }
              else{
                hasmore = false
              }
      这样改了,上拉的时候显示没有更多数据,你说的这个要怎么改?
      08-06
      回复
    • 小黎
      小黎
      08-06回复蓝天☁
      你要判断你的总数据还有没有啊,有就允许上拉加载,没有就显示暂无数据,你这里判断大于5是啥意思
      08-06
      回复
    • 蓝天☁
      蓝天☁
      08-06回复小黎
      这个5就是一次显示的5条数据
      08-06
      回复
    查看更多(1)
登录 后发表内容