Saturday 15 March 2014

javascript - AngularJS - Mapping a date from a range of dates -



javascript - AngularJS - Mapping a date from a range of dates -

i have table in header, produces 12 cells start current date, subtracting 1 month, so:

22 oct 2014 | 22 sep 2014 | 22 aug 2014 etc etc

i have json file list of dates. have angular service retrieves dates however, trying do, compare range of dates in header, counts how many items json, fall in between dates.

here's plunker: http://plnkr.co/edit/8ncklxradtosc0en2swg?p=preview

html:

<table> <thead> <tr> <th></th> <th ng-repeat="months in getmonths track $index">{{ months }}</th> </tr> </thead> <tbody> <tr> <td></td> <td ng-repeat="months in getmonths track $index"> <span ng-repeat="item in filtered = (datemapping(months))"></span> <p>{{filtered.length}}</p> </td> </tr> </tbody> </table>

js:

so, output like:

22 oct 2014 | 22 sep 2014 | 22 aug 2014 etc etc 2 | 5 | 0 etc etc

update:

$scope.datemapping = function(months) { var curdate = new date(months); var prevdate = new date(months); prevdate = new date(new date(prevdate.setmonth(prevdate.getmonth() - 1)).setdate(prevdate.getdate() - 1)); //console.log("curdate: " + curdate); //console.log("prevdate: " + prevdate); var jsonentries = $scope.dates; (var = 0; < jsonentries.length; i++) { var jsondate = jsonentries[i].date.substring(6, jsonentries[i].date.length - 2); if (jsondate >= curdate && jsondate <= prevdate ) { //perform .push } else { } } };

javascript jquery angularjs angularjs-scope angularjs-ng-repeat

No comments:

Post a Comment