无法读取未定义对象数组列表的属性0

时间:2019-04-06 14:56:50

标签: javascript arrays polymer

我正在尝试更改对象数组的数据。为此,我首先必须找到正确的对象,但是当我尝试获取数据时会损坏。并说它无法读取未定义的属性0。

class PresentielijstApp extends Polymer.Element {
  static get is() { return 'presentielijst-app'; }
  static get properties() {
    return {
      DummyStudents: {
        type: Array,
        value: [
          {name : "Peter", surname : "de Vries", studentnum : 123321, present : false, Absence :  true},
          {name : "Koos", surname : "Achterhoek", studentnum : 324432, present : true, Absence :  false},
          {name : "Freek", surname : "Vonk", studentnum : 234432, present : false, Absence :  true},
          {name : "Violette", surname : "Zayas", studentnum : 320432, present : true, Absence :  false},
          {name : "Marvin", surname : "Alday", studentnum : 546650, present : false, Absence :  true},
          {name : "Helen", surname : "Hong", studentnum : 476747, present : true, Absence :  false},
          {name : "Donetta", surname : "Minnix", studentnum : 534590, present : false, Absence :  true},
          {name : "Alesia", surname : "Basham", studentnum : 356897, present : true, Absence :  false},
          {name : "Lyn", surname : "Flewelling", studentnum : 365354, present : false, Absence :  true},
          {name : "Gilberte", surname : "Wafer", studentnum : 432423, present : true, Absence :  false},
          {name : "Margeret", surname : "Hundt", studentnum : 123124, present : false, Absence :  true},
          {name : "Lavinia", surname : "Kimmons", studentnum : 543365, present : true, Absence :  false},
          {name : "Jc", surname : "Schmit", studentnum : 346559, present : false, Absence :  true},
          {name : "Alvin", surname : "Capers", studentnum : 324409, present : true, Absence :  false},
          {name : "Amira", surname : "Croslin", studentnum : 534908, present : false, Absence :  true},
          {name : "Louanne", surname : "Berkman", studentnum : 348976, present : true, Absence :  false},
          {name : "Jerry", surname : "Nurse", studentnum : 978943, present : false, Absence :  true},
          {name : "Amiee", surname : "Belgarde", studentnum : 213120, present : true, Absence :  false}
        ]
      }
    };
  }

  //Change students present data  
  absenceHandler(){
    var DummyStudents = this.get(['DummyStudents']);
    var i;
    var j = DummyStudents.length;
    var studID = 543365;
    console.log(j)
    for (i = 0; i < j; i++) { 
      if(DummyStudents.studentnum[i] == studID){
        console.log("BOIS WE GOT M")  
      }
    }
  }

0 个答案:

没有答案