我不知道如何从切换列表中检索值。每个切换代表学生是否在上课。
下面有一个提交按钮,当按下该按钮时,会将触发器上带有“ false”值的学生发送到数据库中。
我不知道如何获取此信息,使用Ionic Angular似乎很棘手。
我尝试在.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);
}
}
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函数将其发送到数据库。
答案 0 :(得分:1)
还有另一种简单的方法。 在signalAbsence(event,i)中,可以添加an数组,然后将真实值推入该数组,然后将false推入另一个数组,然后将所需的内容从这些推入数据库。
答案 1 :(得分:0)
最后,我将切换功能中的this.students部分更改为... this.students [i] .value = true;
这为每一行提供值,而不是数组中的行集合。
感谢您的输入。