离子3 - 推入物体阵列

时间:2018-03-21 17:49:56

标签: arrays object ionic-framework push

我正在尝试从firebase中推送一个对象数组并将其存储到我的阵列出勤中。但我的代码不起作用。知道怎么做吗?

在for循环中,我试图检查我是否正在获取数据并且它会迭代学生的名字。但看起来循环停止时它会触及我将数据推送到本地数组的代码(出勤[])

export class CheckAttendancePage {

  public attendance: any[]
  public student: any[]

  constructor( private attendanceList: AttendanceListService, 
   public navCtrl: NavController, public navParams: NavParams) {

    attendanceList.getStudentsList().valueChanges().subscribe(students => {
      this.student = students;

      for (let index = 0; index < this.student.length; index++) {
        console.log(index)
        console.log(this.student[index].name)

        // problem here
        this.attendance.push({
        'studentName': this.student[index].name,
        'status': ''
        })
     }
     console.log("attendance", this.attendance)

  })
}

0 个答案:

没有答案