我想循环一个名为数据的数组,在另一个数组中填充'冠军'这是什么正确的语法?我可以高兴地循环我所有的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 –