我不知道如何从切换列表中检索值。每个切换代表学生是否在类。
下面有一个提交按钮,按下该按钮时,会将那些开关上值为“false”的学生发送到数据库中。
我不知道如何获取这些信息,使用 Ionic Angular 似乎很棘手。
我尝试向 .ts 文件上的函数添加 if 函数,但它不喜欢我添加的“值”。
<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);
}
}
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]);
}
}
所以我需要知道哪些学生有错误值,然后如何使用该信息并使用此代码底部的 signalAbsence 函数将其发送到数据库。
最佳答案
还有另一种更简单的方法。 在 signalAbsence(event,i) 中,您可以添加一个数组并将真值推送到该数组中,并将假值推送到另一个数组中,然后将您想要的值推送到数据库中。
关于javascript - 从切换列表中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57199914/