undefinedfix
Sign in

In the for of loop, how to make it pop up only once

aeryk edited in Mon, 08 Aug 2022
// resp.data 表示一个对象数组, 遍历一下
for(let v of resp.data) {   
    // 验证employdFlag是不是True  和accidentFlag 是不是Flase.如果是 push到employees
    if(v.employedFlag && !v.accidentFlag) {
      this.employees.push({employeeId:v.employeeId})
    } else {
      // 如果不是 那就给他提示
      this.loading = false;
      this.$Message.error(`${v.snCardId}已办理团险!`);
      break;
    }
  }

But the result is always unsatisfactory (┬┬)... When there are three prompts, three pop up, as shown in the figure below

What we need to do is:

[No 1, 2, 3 ID card records]

Do you have a big idea? Demo is better.

Originally, we used map, but it seems that map can't return. We can't use this,,....

3 Replies
tanish
commented on Mon, 08 Aug 2022
var errMessage=[];//需要提示的序号

// resp.data 表示一个对象数组, 遍历一下
for(let v of resp.data) {   
    // 验证employdFlag是不是True  和accidentFlag 是不是Flase.如果是 push到employees
    if(v.employedFlag && !v.accidentFlag) {
      this.employees.push({employeeId:v.employeeId})
    } else {
      // 如果不是 那就给他提示
      errMessage.push(v.snCardId);
    }
  }
      if (errMessage.length>0){
          this.loading = false;
          this.$Message.error(' '+errMessage.join(',')+`已办理团险!`);
      }

CMPND
commented on Mon, 08 Aug 2022

Need to prompt the array also installed, and then unified prompt is good

user3345808
commented on Mon, 08 Aug 2022

You need to prompt to push into an array. After the loop, you can judge whether there is any prompt in the array. If there is one, you will be "None" + ['1 ','2','3 ']. Join ("," + "ID card record"

lock This question has been locked and the reply function has been disabled.