I'm binding JSON objects to a list, but I only want to show one (the first, since the results are ordered) item per user. The JSON I'm getting back is per item, with a user object as a property (item.user.username, etc.). With jQuery I'd do something like:
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);
}
}
But is there a more Angular-thonic way to do this? I've been looking at filters but can't figure out an easy way (other than iterating through the bound data like above) to do this.
UPDATE:
AngularJS code is a little much to post, but basically I have a $scope.items array of JSON objects in my controller that I get via an API courtesy of $http and an ItemFactory, and pretty basic HTML to display things:
<ul id="items">
<li class="item" data-ng-repeat="item in items">
{{item.title}} | {{item.posted}}
</li>
</ul>