if else语句实现不了?
发布于 5 年前 作者 wujuan 6624 次浏览 来自 官方Issues

state初始值为0,在下拉中,if state=0,就执行more事件,否则不执行。more事件中如果获取不到更多数据就将state的值置为1.

data:{
state:0
},

onReachBottom: function () {
    let state=state
    if(state ==0){
    this.more()
  }
    else{
      console.log("空")
    }
  },

  more: function () {
    const db = wx.cloud.database();
    let x = this.data.list_nums + 20
    let old_data = this.data.list
    db.collection('order').skip(x).get()
      .then(res => {
        if(res.data==null || res.data==0 || res.data==" "){
          console.log("为空")
          wx.showLoading({
            title: '没有更多数据了',
            duration: 800
          })
          this.setData({
            state:1 //没有更多数据就将state置1
          })
        }
        else{
        this.setData({
          list: old_data.concat(res.data),
          list_nums: x
        })
          console.log(res.data)}
      })
      .catch(err => {
        console.error(err)
      })
  },
2 回复
let state=state
是什么鬼   state值哪来的?   

let state= this.data.state
吧?

一楼正解

回到顶部