我正在尝试从API - https://sportsbook.draftkings.com/api/odds/v1/leagues/3/offers/gamelines.json获取数据。和https://www.fantasylabs.com/api/sportevents/3/2019_06_17
我使用forkJoin连接了2个API。
在API- https://sportsbook.draftkings.com/api/odds/v1/leagues/3/offers/gamelines.json中,我成功访问了line列。但在检索数据时,它会获取name为line的所有数据。我只想访问每一场比赛的第一次出现的线路。例如第一场比赛的"line": "+3.5000"
。然后使用"line": "+46.0000"
进行第二个游戏,依此类推
我还发现很难访问两个团队的oddsAmerican数据。例如在第一场比赛中,我有兴趣获取的数据是第一场比赛的"oddsAmerican": "+148"
和"oddsAmerican": "-182"
以下是我的代码
y.component.ts
import {Component} from '@angular/core';
import {HttpClient} from '@angular/common/http'
import {forkJoin} from 'rxjs';
import {map} from 'rxjs/operators';
@Component({
selector: 'app-mlb-api',
templateUrl: './mlb-api.component.html',
styleUrls: ['./mlb-api.component.css']
})
export class MlbApiComponent {
allName;
//allawayTeamName;
allline;
allmoneyLine;
//all: Array<{line: string, awayTeam: string, homeTeam: string}> = [];
all: Array<{line: string, name: string, moneyLine:string}> = [];
constructor(private http: HttpClient) {}
ngOnInit() {
const character = this.http.get('https://sportsbook.draftkings.com/api/odds/v1/leagues/3/offers/gamelines.json').pipe(map((re: any) => re.events));
const characterHomeworld = this.http.get('https://www.fantasylabs.com/api/sportevents/3/2019_06_17');
forkJoin([character, characterHomeworld]).subscribe(([draftkingsResp, fantasylabsResp]) => {
this.allName = draftkingsResp.map(r => r.name);
//this.allawayTeamName = draftkingsResp.map(r => r.awayTeamName);
this.allline = draftkingsResp.map(r=>r.offers).flat().map(r => r.outcomes).flat().map(o => o.line);
this.allline = this.allline.filter(l => !!l);
this.allmoneyLine = draftkingsResp.map(r=>r.offers).flat().map(r => r.outcomes).flat().map(o => o.oddsAmerican);
this.createAllArray();
});
}
createAllArray(): void {
for (let i = 0; i < this.allline.length; i++) {
let item = {
line: this.allline[i],
name: this.allName[i],
moneyLine: this.allmoneyLine[i]
//homeTeam: this.allhomeTeamName[i]
}
this.all.push(item);
}
}
}
y.component.html
<table class="table table-striped table-condensed table-hover">
<thead>
<tr>
<!-- <th class="awayTeamName">awayTeamName <a ng-click="sort_by('awayTeamName')"><i class="icon-sort"></i></a></th>
<th class="field3">homeTeam <a ng-click="sort_by('HomeTeam')"><i class="icon-sort"></i></a></th> -->
<th class="name">Name <a ng-click="sort_by('name')"><i class="icon-sort"></i></a></th>
<th class="line">Line <a ng-click="sort_by('line')"><i class="icon-sort"></i></a></th>
<th class="line">Money Line <a ng-click="sort_by('money_line')"><i class="icon-sort"></i></a></th>
</tr>
</thead>
<tbody>
<ng-container *ngFor="let item of all | paginate: { itemsPerPage: 5, currentPage: p }; let i = index">
<tr>
<td>{{item.name}}</td>
<td>{{item.line }}</td>
<td>{{item.moneyLine}}</td>
</tr>
</ng-container>
</tbody>
</table>
<pagination-controls (pageChange)="p = $event"></pagination-controls>
https://stackoverflow.com/questions/56758807
复制相似问题