鍍金池/ 問答/HTML/ 報錯Cannot read property 'length' of undef

報錯Cannot read property 'length' of undefined ?

報錯如下:
Uncaught TypeError: Cannot read property 'length' of undefined
請問是哪里出問題了, 該怎么解決, 謝謝
html


  changeIndex (index){
    console.log(index)
    this.activeIndex = index
    this.sportDatabaseOrderBy = this.sportDatabase.slice(0) // 數(shù)組深拷貝
    for (let i = 0; i < this.sportDatabaseOrderBy.length; i++) {
       let firstLetter = py.getFullChars(this.sportDatabaseOrderBy[i].name).slice(0,1)
       this.sportDatabaseOrderBy[i].firstLetter = firstLetter
    }
  }
回答
編輯回答
深記你

你的this.sportDatabaseOrderBy是underfined,你檢查下this.sportDatabase

2017年4月25日 20:29
編輯回答
淺時光

在for loop時, this.sportDatabaseOrderBy是undefined.

2017年8月5日 18:17
編輯回答
尐飯團

在這鐘報length錯誤的情況下,一般都是這個值是undefined,或是特殊情況下取不到

2018年9月3日 06:11
編輯回答
萌吟

檢查this.sportDatabaseOrderBy是否有值

2018年6月19日 19:22