I am trying to group the elements in an array that have the same id using angular js Filter
I have this filter:
.filter('groupBySectionNum', function(){
return function(items){
if(items){
var finalItems = [];
for (var i = 0; i < items.length; i++) {
var _id = items[i]._id;
if(!finalItems[_id]){
finalItems[_id]=[];
}
finalItems[_id].push(items[i]);
}
return finalItems;
}
}
})
which uses the is as an index so that it groups objects with similar id
the results wont show up in the html
<a ng-repeat="a in (filteredSecs = cal|groupBySectionNum)">
<accordion-group heading="try">
something {{a[0]._id}}
</accordion-group>
</a>
how can i properly group the items? or properly read the filtered array?
finalItems
should not be an array, it should just be an object. Arrays should have contiguous indices (even though JavaScript allows what you're doing). – jelinson Mar 2 at 8:19