for循环TypeError: Cannot read property '0' of undefi
发布于 5 年前 作者 na04 11024 次浏览 来自 官方Issues
updata(e){ 
    this.data.staffId=app.globalData.staffId
    this.data.status=1
    var dish=e.currentTarget.dataset.dishName
    var tableId=+e.currentTarget.dataset.table
    
    for (let i=0; i < this.data.length; i++) {
      if(this.data.noticeList[i].dishName==dish&this.data.noticeList[i].table==tableId){
        this.data.noticeList[i].status=1
        console.log(this.data.noticeList[i].status)
        break
      }
    }
    this.hideModal(e)
  },

2 回复

1.你确定要data的长度吗?this.data.length

2.检查下this.data.noticeList是否为数组?可以console.log下

你这写的什么for循环,明显错误,data都不是个array

回到顶部