我有一个JSON对象,我想在angular2 typescript类中表示。 JSON对象中有它自己类型的对象数组。 JSON对象是这样的:自引用类型脚本类
{
"data": {
"id": 5
"type": "taxons",
"attributes": {
name: "Vehicles & Vehicle Accessories",
"taxons": [{
"id": 8,
"type": "taxons",
"attributes": {
name: "Make",
"taxons": []
},
"id": 9,
"type": "taxons",
"attributes": {
name: "Model",
"taxons": []
}
}]
}
}
当我创建打字稿中taxon
模型,我陷入了如何代表自己的taxons
数组中引用taxon
。 我目前有这样的班级。
export class Taxon {
constructor (
public id: number,
public name: string,
public taxons: //I am stuck here.
)
}
如何获得参考self
,这样我可以有类似
public taxons: Array<self>
还是怎么回事,我能做到这一点,以获得预期的行为。