TypeError无法读取未定义的属性“ push”

时间:2019-07-29 07:28:45

标签: angular

当数据推入Array时,它导致typeerror无法读取未定义的属性“ push”。我想为每个循环将数据添加到数组中

if (s > 0) {
        for (let key in result.shiftStatusList) {
          var data = result.shiftStatusList[key];
          this.shiftStatusList = data.status;
          this.shiftName = data.shiftName;
          for (let mod in data.centreStatusList) {
            var moderator = data.centreStatusList[mod]
            this.centreStatusList = moderator.status
            this.moderatorView = true;

            for (let sup in moderator.hallStatusList) {
              var Supervisor = moderator.hallStatusList[sup]
              this.hallStatusList = Supervisor.status;
              this.SupervisorView = true;
              if (this.hallStatusList == "INCOMPLETE") {
                break;
              }
            }
          }
      }
      this.Shift.push({ shiftStatusList: this.shiftStatusList, shiftName: this.shiftName, centreStatusList: this.centreStatusList, hallStatusList: this.hallStatusList });


    }

1 个答案:

答案 0 :(得分:0)

将shift变量分配给一个空数组,如下所示。

Shift: any[] = [];