【发布时间】:2016-03-07 15:52:35
【问题描述】:
我有一个 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": []
}
}]
}
}
当我在 typescript 中创建 taxon 模型时,我陷入了如何在 taxons 数组中表示自引用 taxon 的问题上。
我目前有这样的课程。
export class Taxon {
constructor (
public id: number,
public name: string,
public taxons: //I am stuck here.
)
}
我如何获得对self 的引用,以便我可以拥有类似的东西
public taxons: Array<self>
或者我还能怎么做才能获得预期的行为。
【问题讨论】:
标签: angularjs typescript angular self-reference