我有一个递归的json结构,如下所示,我想以角度动态渲染html视图模板。
关键如下:只要它具有属性对象,它可能具有属性对象或对象,其中对象始终是一个数组,对象始终是一个对象。它可能会无限循环,具体取决于json。
我已经将视图定义如下,但是我在视图中定义的深度有限,而视图应该根据json呈现。
的index.html
<div ng-repeat="subtopic in json.subtopic">
<div ng-if="subtopic.objects">
<div ng-repeat="subtopic in subtopic.objects">
<div ng-if="subtopic.objects">
</div>
</div ng-if="object">
</div>
</div>
</div ng-if="object">
</div>
</div>
<div ng-if="object">
</div>
</div>
JSON.json
{
subtopic: [
{
"title": "title 1",
"subtitle": "title 2",
"objects": [{
"title": "123"
"label": "456"
"objects": [
{
"object": {
"object-1": "123",
"object-2": "456"
}
},
{
"object": {
"object-1": "123",
"object-2": "456"
}
}
]
}]
},
{
"title": "title 1",
"subtitle": "title 2",
"objects": [{
"title": "123"
"label": "456"
"objects": [
{
"object": {
"object-1": "123",
"object-2": "456"
}
},
{
"object": {
"object-1": "123",
"object-2": "456"
}
}
]
}]
},
]
}