I am currently working on binding JSON objects to a list, with the requirement of displaying only one item per user (specifically the first since they are ordered). The structure of the JSON data includes a user object as a property for each item (item.user.username, etc.). In jQuery, I would approach this task like so:
var arr = ... JSON objects ...
var seen_users = [];
var items = [];
$.each(arr, function(i, item){
if (!$.inArray(item.user.id, arr) === -1){
items.push(item);
seen_users.push(item.user.id);
}
}
However, I am exploring more AngularJS-friendly options to achieve the same result. I have looked into filters but haven't found an easier way than iterating through the data using the above method.
UPDATE:
My AngularJS code is quite complex to explain in detail here, but essentially, I have a $scope.items array containing JSON objects fetched from an API using $http and ItemFactory. The HTML markup for displaying these items is fairly basic:
<ul id="items">
<li class="item" data-ng-repeat="item in items">
{{item.title}} | {{item.posted}}
</li>
</ul>