I'm trying to figure out how to handle dynamic JSON responses with a single angular template. Below are two examples of the same template, but different JSON responses (somewhat similar). I'm trying to figure out how to handle both (and quite possibly more) of these responses in the same template. Essentially how do I handle UNKNOWN levels in a json response?
http://plnkr.co/edit/1H9AfwUYvcYVEBmBb0Ln?p=preview
{"book": {
"title": "Book Title",
"chapters": [
{
"title": "Chapter One",
"units": [
{
"title" : "Unit One",
"sections": [
{"title" : "Section One"},
{"title" : "Section Two"},
{"title" : "Section Three"}
]
},
{"title" : "Unit Two"},
{"title" : "Unit Three"}
]
},
{"title": "Chapter Two"},
{"title": "Chapter Three"}
]
}};
http://plnkr.co/edit/8S6iCrF3A72MNEpKEhMu?p=preview
{"book": {
"title": "Book Title",
"chapters": [
{
"title": "Chapter One",
"sections": [
{"title" : "Section One"},
{"title" : "Section Two"},
{"title" : "Section Three"}
]
},
{"title": "Chapter Two"},
{"title": "Chapter Three"}
]
}};
Template:
<div ng-repeat="item in book">
{{item.title}}
<ul>
<li ng-repeat="chapter in item.chapters">
{{chapter.title}}
<ul>
<li ng-repeat="unit in chapter.units">
{{unit.title}}
<ul>
<li ng-repeat="section in unit.sections">
{{section.title}}
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
childrenso at each level you can doif children.length. Can put the sub headings likechapterin same name properties also at each level....other properties liketextorcontent. keep structure consistent and it will all fall into place