javascript - 遍历数组将对象push()到新数组里面,在vue里面一直出错
阿神
阿神 2017-04-11 13:13:23
[JavaScript讨论组]

需求:遍历数组,用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就不报错了,但是这样又租不到需求,请问这是什么原因?
阿神
阿神

闭关修行中......

全部回复(1)
PHP中文网
    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])
        }
      }
    })
  }
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号