亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么我的數組在函數返回后會發生變化?

為什么我的數組在函數返回后會發生變化?

慕沐林林 2022-09-11 20:12:48
我有一個函數,在其中我過濾一個數組,并在復選框的幫助下檢查對象的屬性是否等于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>
查看完整描述

1 回答

?
吃雞游戲

TA貢獻1829條經驗 獲得超7個贊

我認為你錯誤地使用了rxjs,試試這個


getGetLikedMatches(checked) {

    this.sp.getReleases().subscribe(data => {

       this.allMatches = data;


       if (checked) {

           this.matches = this.allMatches.filter(match => match.favorit == 1);

       } else {

           this.matches = data;

       }


       console.log({ matches: this.matches, allMatches: this.allMatches });

});

}


查看完整回答
反對 回復 2022-09-11
  • 1 回答
  • 0 關注
  • 124 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號