javascript - Group items by month and display them in a two nested lists in Angular.js -
i have list of items. each item contains date property. want group items month , display them in 2 nested lists.
example
june 2015
- item 1
- item 2
- item 3
may 2015
- item 4
- item 5
- item 6
etc.
is possible achieve in angular.js without fiddling underlying data (i.e. via filters , such)?
i've tried method described in topic: how can group data angular filter?, breaks order of elements , have manually format date 'mmmm yyyy' before calling groupby.
looks pretty straight forward, group items date , display :
var itemsgroupedbymonth = function (items) { var groups = [[], [], [], [], [], [], [], [], [], [], [], [],], itemgroupedbymonths = []; (var = 0; < items.length; i++) { groups[items[i].date.getmonth()].push(items[i]); } (var = 0; < groups.length; i++) { if (groups[i].length) { itemgroupedbymonths.push({ month: monthlabels[i], items: groups[i] }); } } return itemgroupedbymonths; }; find working example here : http://plnkr.co/edit/idvlofkofvwgdbsgfmsx?p=preview
Comments
Post a Comment