我想循環一個名爲數據的數組,在另一個數組中填充'冠軍'這是什麼正確的語法?我可以高興地循環我所有的IChampion內的冠軍,但我似乎無法循環的IChampionData []我如何循環一個類中的數組 - 角2 2
IChampion.ts
import { IChampionData } from "./champion-data";
export interface IChampion {
type: string;
format: string;
version: string;
data: IChampionData[];
}
HTML
<div class='table-responsive'>
<table class='table table-striped'>
<thead>
<tr>
<th>Champion Name</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let champion of champion">
<td>{{champion1.name}}</td>
</tr>
</tbody>
</table>
數據是我想要循環的,我在IChampionData中有一個名爲name的變量,我不知道如何獲取變量。
這裏是JSON的一個例子
"data": {
"Aatrox": {
"version": "6.24.1",
"id": "Aatrox",
"key": "266",
"name": "Aatrox",
"title": "the Darkin Blade",
"blurb": "Aatrox is a legendary warrior, one of only five that remain of an ancient race known as the Darkin. He wields his massive blade with grace and poise, slicing through legions in a style that is hypnotic to behold. With each foe felled, Aatrox's ...",
"info": {
"attack": 8,
"defense": 4,
"magic": 3,
"difficulty": 4
},
"image": {
"full": "Aatrox.png",
"sprite": "champion0.png",
"group": "champion",
"x": 0,
"y": 0,
"w": 48,
"h": 48
},
"tags": [
"Fighter",
"Tank"
],
"partype": "BloodWell",
"stats": {
"hp": 537.8,
"hpperlevel": 85.0,
"mp": 105.6,
"mpperlevel": 45.0,
"movespeed": 345.0,
"armor": 24.384,
"armorperlevel": 3.8,
"spellblock": 32.1,
"spellblockperlevel": 1.25,
"attackrange": 150.0,
"hpregen": 6.59,
"hpregenperlevel": 0.5,
"mpregen": 0.0,
"mpregenperlevel": 0.0,
"crit": 0.0,
"critperlevel": 0.0,
"attackdamage": 60.376,
"attackdamageperlevel": 3.2,
"attackspeedoffset": -0.04,
"attackspeedperlevel": 3.0
}
}
這裏是我嘗試在模型
import { IChampionStats } from './champion-stats';
import { IChampionImage } from './champion-image';
import { IChampionInfo } from './champion-info';
export interface IChampionData {
version: string;
id: string;
key: string;
name: string;
title: string;
blurb: string;
info: IChampionInfo[];
image: IChampionImage[];
tags: string[];
partype: string;
stats: IChampionStats[];
}
什麼是實際的JSON,因爲JSON似乎只是內部JSON的一個片段,因爲它不匹配所有的接口? – Alex
這是完整的json文件:https://pastebin.com/ncBhC2tH –