ich dies für Schleife, wo ich Benutzer den FortschrittFor-Schleife zeigt nur zuletzt von Feuerbasis
Typoskript abrufen:
his.userProgress = af.object('/UserProgress/' + this.currentUser + '/', { preserveSnapshot: true });
this.userProgress.subscribe(snapshots => {
snapshots.forEach(snapshot => {
this.userScores.push(snapshot.val());
});
console.log(this.userScores);
//set this one to i<=8 because total no. of quizzes are 9. which means this.userScores.length -1
for(var i=0; i <= 8; i++){
if (this.userScores.length == i) {
this.scores = [{
None: "Nothing Recorded"
}];
console.log("Nothing");
}
else if (this.userScores.length >= i) {
this.scores = [{
Chapter:this.userScores[i].Chapter_Quiz,
QuizNo:this.userScores[i].Quiz,
Score:this.userScores[i].Score,
}];
console.log("With Scores");
}
}
});
Erstens, es prüft, ob die userScores ist [] Länge weniger 0 oder größer als oder gleich 0. Wenn es für dieses Quiz keine Punktzahl gibt, wird "Nichts aufgezeichnet" angezeigt, andernfalls wird die Punktzahl angezeigt.
HTML:
<ion-card>
<ion-list *ngFor="let score of scores">
<ion-card-header>
{{score.Chapter}}
</ion-card-header>
<button ion-item *ngIf="scores.length < 0">
<ion-icon name="planet" item-start></ion-icon>
{{score.None}}
</button>
<button ion-item *ngIf="scores.length >= 0">
<ion-icon name="planet" item-start></ion-icon>
{{score.Score}}
</button>
</ion-list>
ich Probleme mit bin, wo es nur der letzte Datensatz zeigt. Was mache ich falsch?
Erwartete Ausgabe:
If finished with the 1st quiz:
1st: Score
2nd: Nothing Recorded
3rd: Nothing Recorded
....
if no score at all:
1st: Nothing Recorded
2nd: Nothing Recorded
.....
Welches der Protokolle zeigt? – Vega
@Vega zeigt nur MitAdapt an. Ich habe die Ausgabe von meiner console.log hinzugefügt – AngularNewbie