xiaozuoqiang 2021-07-20 09:45 采纳率: 40%
浏览 374
已结题

怎么解决vue里面第二个forEach不工作

js代码

//获取组织用户成绩列表
    getUserList() {
      this.listQuery.OrgId = this.temp.parentId;
      var _this = this;
      // this.listQuery.CourseId = this.Classvalue;
      // console.log(this.listQuery);
      //获取用户
      users.getList(this.listQuery).then((response) => {
        //连接查询
        this.userList = [];
        this.List = response.data;
        // 遍历成绩表
        this.List.forEach((item) => {
          console.log(this.ScoreList);
          this.ScoreList.forEach((item1) =>{
            console.log(item.id == item1.userId);
            if(item.id == item1.userId){//判断用户id和课程表里的id是否相等   
              item.scoreId = item1.id;
              item.score = item1.score;
              item.status = 200;
            }
          }); 
          if (item.score == undefined) {
            item.score = 0;
          }
          this.userList.push(item);
        });
        console.log(this.userList);
        _this.total = response.count;
      });
    },
    //获取成绩列表
    getScoreList() {
      this.ScoreList = [];
      queryClass
        .getCourseScore({ page: 1, limit: 500, key: undefined })
        .then((res) => {
          console.log(res.data);
          console.log(this.Classvalue);
          res.data.forEach((item) => {
            if (item.courseId == this.Classvalue) {
              this.ScoreList.push(item);
            }
          });
          console.log("这是成绩列表");
          console.log(this.ScoreList);
        });
    },

  //查询成绩
    queryScore() {
      this.getScoreList();
      this.getUserList();
    },

这是有时候点击查询会出现的效果
img

img

这是正常工作的效果
img

img

  • 写回答

3条回答 默认 最新

  • 禅思院 前端领域优质创作者 2021-07-23 09:46
    关注

    跟map 没关系

    
        //获取成绩列表
        getScoreList() {
          this.ScoreList = [];
          queryClass
            .getCourseScore({ page: 1, limit: 500, key: undefined })
            .then((res) => {
              console.log(res.data);
              console.log(this.Classvalue);
              res.data.forEach((item) => {
                if (item.courseId == this.Classvalue) {
                  this.ScoreList.push(item);
                }
              });
              console.log("这是成绩列表");
              console.log(this.ScoreList);
            });
        },
     
      //查询成绩
        queryScore() {
          this.listQuery.OrgId = this.temp.parentId
          Promise.all([users.getList(this.listQuery), this.getScoreList()]).then(res=> {
            //连接查询
            this.userList = [];
            this.List = res[0].data;
            // 遍历成绩表
            this.List.forEach((item) => {
              console.log(this.ScoreList);
              this.ScoreList.forEach((item1) =>{
                console.log(item.id == item1.userId);
                if(item.id == item1.userId){//判断用户id和课程表里的id是否相等   
                  item.scoreId = item1.id;
                  item.score = item1.score;
                  item.status = 200;
                }
              }); 
              if (item.score == undefined) {
                item.score = 0;
              }
              this.userList.push(item);
    
              console.log(this.userList);
              this.total = res[0].count;
          })
        },
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 7月31日
  • 已采纳回答 7月23日
  • 修改了问题 7月20日
  • 创建了问题 7月20日

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题