Currently, I am faced with the challenge of filtering through a nested JSON array within AngularJS. The JSON structure I am dealing with is as follows:
articles_data: [{
title: 'Bigfoot Afoot',
tags: ['True stories', 'forests'],
description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dapibus mi at nulla finibus pretium. Curabitur auctor lacus vitae varius viverra. Sed pharetra varius sapien, id hendrerit ipsum lacinia placerat. Morbi vitae neque ipsum. Curabitur sem neque, iaculis vel nisl a, condimentum commodo arcu. Morbi nec urna efficitur, tempor nisl a, aliquet felis. Ut non est massa. Proin eget purus est. Integer eu nisi sed nisi maximus sodales. Duis finibus turpis a velit consectetur, luctus eleifend metus scelerisque. Pellentesque suscipit iaculis purus vel convallis.",
category: 'Bigfoot'
},
{
title: 'Lockness Sighted!',
tags: ['Sightings', 'Lakes'],
description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dapibus mi at nulla finibus pretium. Curabitur auctor lacus vitae varius viverra. Sed pharetra varius sapien, id hendrerit ipsum lacinia placerat. Morbi vitae neque ipsum. Curabitur sem neque, iaculis vel nisl a, condimentum commodo arcu. Morbi nec urna efficitur, tempor nisl a, aliquet felis. Ut non est massa. Proin eget purus est. Integer eu nisi sed nisi maximus sodales. Duis finibus turpis a velit consectetur, luctus eleifend metus scelerisque. Pellentesque suscipit iaculis purus vel convallis.",
category: 'Nessy'
},
{
title: 'Jacktalopes Everywhere',
tags: ['Rabbits', 'cities'],
description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dapibus mi at nulla finibus pretium. Curabitur auctor lacus vitae varius viverra. Sed pharetra varius sapien, id hendrerit ipsum lacinia placerat. Morbi vitae neque ipsum. Curabitur sem neque, iaculis vel nisl a, condimentum commodo arcu. Morbi nec urna efficitur, tempor nisl a, aliquet felis. Ut non est massa. Proin eget purus est. Integer eu nisi sed nisi maximus sodales. Duis finibus turpis a velit consectetur, luctus eleifend metus scelerisque. Pellentesque suscipit iaculis purus vel convallis.",
category: 'Jacktalope'
}
]
My current approach involves utilizing an ng-repeat
to iterate through the array:
<div class="col-md-7 articles">
<section>
<div class="card filter" ng-repeat="article in articles.articlemanager.articles track by $index">
<div class="card-header">
{{article.title}} <small>{{article.tags.join()}}</small>
<span class="badge badge-{{article.category}} float-right">{{article.category}}</span>
</div>
<div class="card-body">
<p>
{{article.description}}
</p>
</div>
</div>
</section>
</div>
While this successfully displays the articles, I am now looking to enhance the functionality by implementing filters based on name or tags:
<form>
<div class="form-group">
<label for="filterName">Filter by name</label>
<input type="text" class="form-control" id="filterName">
</div>
<div class="form-group">
<label for="filterTags">Filter by tags</label>
<input type="text" class="form-control" id="filterTags">
</div>
</form>
Although I lack expertise in utilizing filters within AngularJS, I am under time constraints and would greatly appreciate any assistance or guidance. Thank you in advance.