Форум по Javascript
Anonymous
Старая школа рекурсивного Angular 19
Сообщение
Anonymous » 10 янв 2025, 08:03
У меня есть рекурсивный javascript (моя мозговая логика), который я использую в angular 19 для извлечения данных с Youtube. Сценарий работает, но мне интересно, как это лучше сделать, поскольку это мой старый школьный JavaScript.
Спасибо за любые предложения.
Код: Выделить всё
public getSeriesList() {
this.record.webTubeSeries = [];
this._seqNum = 0;
this.getUrlYouTube()
.pipe(first())
.subscribe({
next: (res: any) => {
this.parseVideoList(res["items"]);
if (res['nextPageToken']) {
let repeatGetNextVideoPage = (_token: string) => {
this.getNextVideoPage(_token)
.subscribe(
(result: any) => {
this.parseVideoList(result["items"]);
if (result["nextPageToken"]) {
repeatGetNextVideoPage(result["nextPageToken"]);
}
}
),
(err: any) => {
console.log("HTTP Error", err.message)
}
}
repeatGetNextVideoPage(res["nextPageToken"]);
}
}
}
);
}
private getNextVideoPage(_token: string) {
let url = (this.urlYouTube + this.videoListId + '&pageToken=' + _token);
return this.http.get(url);
}
private parseVideoList(result: any) {
for (let v of result) {
var item = new WebtubeSeries;
item.videoTitle = v.snippet.title;
item.videoId = v.snippet.resourceId.videoId;
if (v.snippet.thumbnails) {
item.urlThumbNailDefault = v.snippet.thumbnails.default.url;
item.urlThumbNailMedium = v.snippet.thumbnails.medium.url;
item.urlThumbNailHigh = v.snippet.thumbnails.high.url;
item.widthDefault = v.snippet.thumbnails.default.width.toString();
item.heightDefault = v.snippet.thumbnails.default.height.toString();
item.widthMedium = v.snippet.thumbnails.medium.width.toString();
item.heightMedium = v.snippet.thumbnails.medium.height.toString()
item.widthHigh = v.snippet.thumbnails.high.width.toString()
item.heightHigh = v.snippet.thumbnails.high.height.toString();
item.seqNumber = this._seqNum++;
//item.id = item.seqNumber;
this.record.webTubeSeries.push(item);
}
}
}
Спасибо.
Подробнее здесь:
https://stackoverflow.com/questions/793 ... angluar-19
1736485423
Anonymous
У меня есть рекурсивный javascript (моя мозговая логика), который я использую в angular 19 для извлечения данных с Youtube. Сценарий работает, но мне интересно, как это лучше сделать, поскольку это мой старый школьный JavaScript. Спасибо за любые предложения. [code]public getSeriesList() { this.record.webTubeSeries = []; this._seqNum = 0; this.getUrlYouTube() .pipe(first()) .subscribe({ next: (res: any) => { this.parseVideoList(res["items"]); if (res['nextPageToken']) { let repeatGetNextVideoPage = (_token: string) => { this.getNextVideoPage(_token) .subscribe( (result: any) => { this.parseVideoList(result["items"]); if (result["nextPageToken"]) { repeatGetNextVideoPage(result["nextPageToken"]); } } ), (err: any) => { console.log("HTTP Error", err.message) } } repeatGetNextVideoPage(res["nextPageToken"]); } } } ); } private getNextVideoPage(_token: string) { let url = (this.urlYouTube + this.videoListId + '&pageToken=' + _token); return this.http.get(url); } private parseVideoList(result: any) { for (let v of result) { var item = new WebtubeSeries; item.videoTitle = v.snippet.title; item.videoId = v.snippet.resourceId.videoId; if (v.snippet.thumbnails) { item.urlThumbNailDefault = v.snippet.thumbnails.default.url; item.urlThumbNailMedium = v.snippet.thumbnails.medium.url; item.urlThumbNailHigh = v.snippet.thumbnails.high.url; item.widthDefault = v.snippet.thumbnails.default.width.toString(); item.heightDefault = v.snippet.thumbnails.default.height.toString(); item.widthMedium = v.snippet.thumbnails.medium.width.toString(); item.heightMedium = v.snippet.thumbnails.medium.height.toString() item.widthHigh = v.snippet.thumbnails.high.width.toString() item.heightHigh = v.snippet.thumbnails.high.height.toString(); item.seqNumber = this._seqNum++; //item.id = item.seqNumber; this.record.webTubeSeries.push(item); } } } [/code] [b]Спасибо.[/b] Подробнее здесь: [url]https://stackoverflow.com/questions/79344658/old-school-recursive-angluar-19[/url]