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

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

angular2函數(shù)去抖的問題

angular2函數(shù)去抖的問題

呼啦一陣風(fēng) 2018-11-22 18:15:54
在angular2環(huán)境中寫了一個自定義的debounce函數(shù),因為使用了服務(wù)中的本地變量,所以沒有使用閉包在傳入函數(shù)作為參數(shù)時,遇到了兩個問題如何給傳入函數(shù)加入?yún)?shù)如何將傳入函數(shù)的作用域綁定在聲明他的component中代碼如下debounceTime(fn, delay) {if (isUndefined(this.timeout)) {this.timeout = setTimeout(() => {            fn();        }, delay);    } else {        clearTimeout(this.timeout);        this.timeout = setTimeout(() => {            fn();        }, delay);    }} emitSubmitDate(event) {    this.submit_data['search'] = event.value;    this.globalFuncService.setInfoListSource(this.request_type, this.request_url,                          this.submit_data);    this.globalFuncService.emitInfoListSource();}staffSearch(event) {    this.globalFuncService.debounceTime(this.emitSubmitDate, 500);}希望將event作為參數(shù)傳入emitSubmit函數(shù),然后再將帶有event的emitSubmit傳入debounce實際遇到的問題是this的變化導(dǎo)致各種undefined本人js不是很好。。。希望各位多多指教
查看完整描述

1 回答

?
慕斯709654

TA貢獻(xiàn)1840條經(jīng)驗 獲得超5個贊

staffSearch(event) {

    this.globalFuncService.debounceTime.apply(this, [() => this.emitSubmitDate(event), 500]);

}

apply變更this指向,也可以用call或bind

傳event則通過一個閉包實現(xiàn)


PS: angular2本身就依賴了Rx,何必自己寫debounceTime....


查看完整回答
反對 回復(fù) 2018-12-30
  • 1 回答
  • 0 關(guān)注
  • 604 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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