【发布时间】:2018-10-31 21:55:18
【问题描述】:
我在 angularJS 中使用 ng-options 创建了两个下拉列表Opening hours 和 Closing Hours。下拉选项由相同的数组填充$scope.availableTimes
以下是 HTML 代码:
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="exampleFormControlSelect1">Opening </label>
<select class="form-control" data-ng-options="time.display for time in availableTimes" data-ng-model="selectedFromTime">
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="exampleFormControlSelect1">Closing</label>
<select class="form-control" data-ng-options="time.display for time in availableTimes" data-ng-model="selectedToTime">
</select>
</div>
</div>
</div>
下面是 AngularJS 脚本
var app = angular.module('angularjs-starter', []);
app.controller('MainCtrl', function($scope) {
$scope.availableTimes = [];
$scope.availableTimes.push({
'msValue': 0,
'display': '12:00 Morning'
});
for (var msValue = 900000; msValue <= 85500000; msValue += 900000) { // 90.000ms = 15 min, 85.500.000ms = 11:45PM
$scope.availableTimes.push({
'msValue': msValue,
'display': moment(msValue).utc().format("h:mm A")
})
}
var dayMS = 86400000 - 1;
$scope.availableTimes.push({
'msValue': dayMS,
'display': '12:00 Midnight'
});
console.log($scope.availableTimes);
});
正如您所看到的,现在两个下拉列表都包含从午夜 12:00 到凌晨 12:00 的时间列表,间隔为 15 分钟。
像这样:
12:00 早上
上午 12 点 15 分
上午 12:30
上午 12 点 45 分
.....
.....
晚上 11 点 45 分
午夜 12:00
What I can do to make the Closing Hour drop-down options lists starts with the value that is 15 min greater than Opening hours.
例子:
如果开放时间选择为上午 8:00 关闭时间下拉列表将从上午 8:15 开始,而不是上午 12:00。
营业时间
12:00 上午
....
....
上午 8:00(已选择)
上午 8 点 15 分
上午 8 点 30 分
....
午夜 12:00
关闭时间
上午 8:00
上午 8 点 15 分
上午 8 点 30 分
.......
.......
12:00 午夜
上午 12 点 15 分
上午 12:30
.......
.......
早上 7 点 45 分
我希望这个例子能说明我想要达到的目标。任何帮助将不胜感激。
【问题讨论】:
-
这与我想要实现的类似,但如何实现这种情况:营业时间周日 11:00am 关闭时间 2:00am
标签: javascript angularjs