第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

等待訂閱在 while 循環(huán)中完成其工作(打字稿)

等待訂閱在 while 循環(huán)中完成其工作(打字稿)

溫溫醬 2023-03-24 16:00:03
我有一個(gè) while 循環(huán),在 while 循環(huán)內(nèi)我有兩個(gè)訂閱。我怎樣才能等他們完成才能繼續(xù)使用 while 循環(huán)?this.counter = 1;array[0] = 3;while(this.counter <= array[0])    {        console.log("WHILE: "+this.counter);        this.ms.getPopular(this.tv, this.counter).subscribe(val => {            this.afstore.collection("matches").doc(this.id).valueChanges().pipe(take(1)).subscribe((val2: any) => {                console.log(this.counter);                if(this.counter == array[0])                {                    return;                }                //console.log("YES");                this.counter++;            });        });        this.counter++;    }我目前的輸出是WHILE: 1WHILE: 2WHILE: 3456但我想要得到的輸出是WHILE: 1123this.counter++在 while 循環(huán)中甚至不需要。如果沒有 while 本身,它就會(huì)無(wú)限運(yùn)行
查看完整描述

1 回答

?
不負(fù)相思意

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超10個(gè)贊

使用遞歸函數(shù)代替循環(huán)。


this.counter = 0;

this.max = 3;


function subscribe() {

  

  this.ms.getPopular(this.tv, this.counter).subscribe(val => {

    this.afstore.collection("matches").doc(this.id).valueChanges().pipe(take(1)).subscribe((val2: any) => {


      if (this.counter == this.max) {

        return;

      } else {

        this.counter++;

        this.subscribe();

      }


    });

  });

}


查看完整回答
反對(duì) 回復(fù) 2023-03-24
  • 1 回答
  • 0 關(guān)注
  • 136 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)