I'm using the filter supplied at Angular ng-repeat with nested json objects? to run through my JSON. However, instead of accessing the 2nd level as in the example there, I need to access all of the 3rd level elements.
My JSON looks like:
[
{
"category": "colors",
"heading": "Colors & Background",
"indexes": [
{
"index": "colors",
"name": "Colors",
"patterns": [
{
"index": "background-patterns",
"name": "Background Patterns"
}
]
}
],
"order": "1"
},
{
"category": "typography",
"heading": "Typography",
"indexes": [
{
"index": "typography",
"name": "Typography",
"patterns": [
{
"index": "headings",
"name": "Headings"
},
{
"index": "plain-text",
"name": "Plain Text"
},
{
"index": "text-icon",
"name": "Text Icon"
}
]
}
],
"order": "2"
}
]
My app.js looks like:
var app = angular.module('mymod', []);
app.filter('createarray', function () {
return function (value, propertyName) {
var arrayList = [];
angular.forEach(value, function (val) {
angular.forEach(val[propertyName], function (v) {
arrayList.push(v)
});
});
console.log(arrayList)
return arrayList;
}
});
app.directive('everything', function() {
return {
restrict: 'E',
templateUrl: 'everything.html',
controller: function($scope, $http) {
$http.get('assets/js/test.json')
.then(function(result) {
$scope.everything = result.data;
});
},
controllerAs: 'everything'
}
});
And my HTML looks like:
<nav class="om-nav-everything">
<ul>
<li ng-repeat="pattern in everything.indexes | createarray: 'patterns'"><a href="index-{{pattern.index}}.html">{{pattern.name}}</a></li>
</ul>
</nav>
What I want to do is have a list item for every pattern, so a list of all 3rd level items from the JSON.
How would I alter the filter to make this happen?
Here is a Plunker with the relevant code: http://plnkr.co/edit/qY4yoBsGTjl9HsreivAN?p=info