Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

需求:遍历数组,用if判断选出符合要求的对象,然后把它push到新的数组里面

图片描述
上代码:
GetAlbumList() {

    let uid = this.$route.query.Uid
    this.$http.get(url, {params: {
      '': this.userInformation
    }}).then((res) => {
      this.aList = res.data.Data.List
      for (let i = 0; i < this.aList.length; i++) {
        if (this.aList[i].Access != 0) {
          console.log(this.aList[i])
          this.albumNameList.push(this.aList[i])
        }
      }
    })
  }
  
 console.log出来的对象都是正确的,在if里面使用push就报错了,除去if条件,用push就不报错了,但是这样又租不到需求,请问这是什么原因?

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
587 views
Welcome To Ask or Share your Answers For Others

1 Answer

    let uid = this.$route.query.Uid
    this.$http.get(url, {params: {
      '': this.userInformation
    }}).then((res) => {
      this.aList = res.data.Data.List;
      if (!this.albumNameList) this.albumNameList = [];
      for (let i = 0; i < this.aList.length; i++) {
        if (this.aList[i].Access != 0) {
          console.log(this.aList[i])
          this.albumNameList.push(this.aList[i])
        }
      }
    })
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...