【发布时间】:2015-07-16 23:43:10
【问题描述】:
我有想要过滤的数据,使用 2 个单独的输入可以正常工作,但我正在尝试将过去 12 个月的月份和年份组合成一个选择。
这些然后填充服务调用,例如:
url.com?month=1&year=2015
目前我有以下
var date = new Date();
var months = [],
monthNames = [ "January", "Febuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
for(var i = 0; i < 12; i++) {
months.push(monthNames[date.getMonth()] + ' ' + date.getFullYear());
date.setMonth(date.getMonth() - 1);
}
$scope.months = months;
填充选择框:
<select id="transMonth" name="transMonth" ng-model="month" class="form-control" ng-options="currMonth as currMonth for currMonth in months" ng-change="fetchTransactions()">
<option value="">-- Please select --</option>
</select>
这当前绑定到单个属性“月”,其值为月份名称年份(例如 2014 年 1 月)我需要将其拆分并更改为数值,即 2014 年 1 月
我该怎么做?
【问题讨论】:
-
也许将
months更改为对象数组?对象可能类似于 {month: 1, year: 2014}。
标签: javascript angularjs