【发布时间】:2018-05-25 09:28:42
【问题描述】:
我有两个不同的数组,英雄:Hero[] 和怪物:Monster[]。它们共享一个名为 totalInitiative 的公共字段。这两个数组需要放入同一个数组中,并按照它们的totalInitiative排序。
我想要达到的目标是这样的:
Array[hero1, hero2, hero3, monster1, monster2]
我创建了一个名为 Participant 的超类:
import {Participant} from './participant';
export class Hero extends Participant{
id: number;
name: string;
player: string;
hitPoints: number;
armor: number;
initModif: number;
imageUrl: string;
totalInitiave: number;
}
import {Participant} from './participant';
export class Monster extends Participant{
id:number;
name: string;
hitPoints: number;
armor: number;
initModif: number;
imageUrl: string;
}
export class Participant{
}
我没有在 Participant 中添加公共字段,因为我有一个 Hero 和一个 Monster 组件,我需要这些公共属性来添加新的 Hero/Monster。
现在我需要调整我的 Encounter 模型,使其包含一个包含 Hero[] 和 Monster[] 的 Participant[]
import {Hero} from './hero';
import {Monster} from './monster';
import {Participant} from './participant';
export class Encounter {
id: number;
name: string;
participants: Participant[ Hero[] Monster[]]; //Doesn't work
}
我什至不确定这是不是正确的方法?
【问题讨论】:
标签: angular typescript components