我正在try 使用以下函数转换来自YouTube搜索API的GET请求.
第一个映射应该为我获取响应对象中的项. 使用第二个映射,我希望将这些项映射到我的Custom Class SearchResult. 但由于某些原因,第二个映射中总是有完整的项目列表,而不是迭代单个元素.因此,管道不会返回带有SearchResult元素数组的可观测对象.
13号角 RxJS 7.5
search(query: string) : Observable<SearchResult[]>{
const params: string = [
`q=${query}`,
`key=${this.apiKey}`,
`part=snippet`,
`type=video`,
`maxResults=10`
].join('&');
const queryUrl = `${this.apiUrl}?${params}`;
return this.http.get(queryUrl).pipe(
map((response : any) => response.items),
map(item => {
return new SearchResult({
id: item.id.videoId,
title: item.snippet.title,
description: item.snippet.description,
thumbnailUrl: item.snippet.thumbnails.high.url
});
}),
)}
}