Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从切换列表中获取值_Javascript_Angular_Ionic Framework_Toggle - Fatal编程技术网

Javascript 从切换列表中获取值

Javascript 从切换列表中获取值,javascript,angular,ionic-framework,toggle,Javascript,Angular,Ionic Framework,Toggle,我不知道如何从切换列表中检索值。每个切换表示学生是否在课堂上 下面有一个提交按钮,按下该按钮时,将向数据库发送带有“false”值的学生 我不知道如何获得这些信息,使用离子角似乎很棘手 我尝试在.ts文件的函数中添加一个if函数,但它不喜欢我添加的“value” <ion-list> <ion-item *ngFor="let student of students; let i = index"> <ion-label>{{ studen

我不知道如何从切换列表中检索值。每个切换表示学生是否在课堂上

下面有一个提交按钮,按下该按钮时,将向数据库发送带有“false”值的学生

我不知道如何获得这些信息,使用离子角似乎很棘手

我尝试在.ts文件的函数中添加一个if函数,但它不喜欢我添加的“value”

<ion-list>
    <ion-item *ngFor="let student of students; let i = index">
      <ion-label>{{ student.nom }}</ion-label>
      <ion-toggle (ionChange)="onChange($event, i)">
      </ion-toggle>
    </ion-item>
    <ion-button (click)="signalAbsence($event, i)">
      Confirmer
    </ion-button>
  </ion-list>

onChange(event, i) {
if (event.target.checked) {
  // this.buttonOn(event, i);
  this.students.value = true;
  console.log(this.students.value, i);
}
else {
  // this.buttonOff(event, i)
  this.students.value = false;
  console.log(this.students.value, i);
}

因此,我需要知道哪些学生有一个错误的值,然后如何使用该信息,并使用代码底部的signal缺席函数将其发送到数据库。

还有另一种更简单的方法。
在signal缺席(event,i)中,您可以添加ann数组,并在该数组中推送真值,在另一个数组中推送假值,然后将所需内容从这些数组推送到数据库。

最后,我将切换函数中的this.students部分改为。。。 this.students[i].value=true

这为每一行提供了值,而不是数组中的行集合

谢谢你的意见

signalAbsence(event, i) {
  event.preventDefault();
//  loop through students to find which have false value, add to array ??
    if (this.students[i].value === false) {
      const date = this.students[0].date;
      const time = this.students[0].time;
      const cours = this.students[0].cours;
      const lieux = this.students[0].lieux;
      const etudiant_nom = this.students[0].nom;
      const etudiant_id = this.students[0].id;
      const url = window.location.href;
      const id = url.substring(url.lastIndexOf('/') + 1);
      this.Auth.updateAbsenceDb(date, time, cours, lieux, id, etudiant_nom, 
    etudiant_id);
      alert("Mis à jour effectué");
      this.router.navigate(['cours/', id]);
} else {
      const url = window.location.href;
      const id = url.substring(url.lastIndexOf('/') + 1);
      alert("Mis à jour effectué");
      this.router.navigate(['cours/', id]);
  }
}