我有一個函數,在其中我過濾一個數組,并在復選框的幫助下檢查對象的屬性是否等于1。liked async getGetLikedMatches(checked){ if(checked){ await this.sp.getReleases().subscribe(data => { this.allMatches = data; this.matches = data; }); this.matches = this.allMatches.filter(match => match.favorit == 1); console.log({matches: this.matches, allMatches: this.allMatches}); // matches has correctly 6 // elements // after the fuction returns matches == allMatches -> 110 element // but why? } else if (!checked){ await this.sp.getReleases().subscribe(data => { this.allMatches = data; this.matches = data; }); console.log(this.matches) }在我的html文件中,我迭代這些匹配項: <div class="col-3" *ngFor="let match of matches"> <img [src]="match.images == '' ? url : getImage(match)" alt="matches" style="min-width: 200px; max-width: 200px; max-height: 200px; min-height: 200px;" (click)="onDetailView(match.id, selectedType)"/> <br /> </div>
為什么我的數組在函數返回后會發生變化?
慕沐林林
2022-09-11 20:12:48