2 回答
TA贡献1796条经验 获得超7个赞
我认为你可以利用startWith.
const term$ = new BehaviorSubject('');
const localStorageResults = localStorage.getItem(''); // Map it into the same shape as results$ but the observable unwrapped
const results$ = term$
.pipe(
startWith(localStorageResults),
debounceTime(1000),
switchMap(term =>
getAutocompleteSuggestions(term)
.pipe(
takeUntil(
//skip 1 value
term$.pipe(skip(1))
)
)
)
)
)
你可能不得不修改它,我不确定它是否会很好,debounceTime但这是一个想法。
TA贡献1831条经验 获得超10个赞
所以在处理了几个小时之后,我发现解决方案非常简单:
autocomplete(1000, (term => new Observable(s => {
const storageValue = this.fetchFromStorage(term);
s.next(storageValue);
this.fetchFromServer(term)
.subscribe(r => s.next(r));
})))
添加回答
举报
