我有一个下拉和文本框,用于计算特定日期的时间,在文本框中输入持续时间,根据下拉列表生成时间段。这适用于一个文本框和一个下拉菜单,但对于多个文本框和下拉菜单,它将为第一个文本框分配相同的值。那么,如何获取每天的多个值以及错误是什么。为了显示多个文本框和下拉列表,我使用了ng-repeat。请帮帮我,如有任何问题请指正。谢谢:)
HTML:
<tr ng-repeat="field in fields" name="slotSelection">
<td align="center">
<ion-checkbox ng-model="field.checked">{{field.name}} </ion-checkbox>
</td>
<td>
<select ng-model="time" ng-options="time for time in timeslots">
<option value="">select</option>
</select>
</td>
<td>
<input type="text" ng-model="interval" ng-blur="setTimeSlots(interval)">
</td>
</tr>
控制器:
$scope.fields = [{ id: 1, name: 'Sunday' },
{ id: 2, name: 'Monday' },
{ id: 3, name: 'Tuesday' },
{ id: 4, name: 'Wednesday' },
{ id: 5, name: 'Thursday' },
{ id: 5, name: 'Friday' },
{ id: 5, name: 'Sunday' }]
$scope.setTimeSlots = function (interval) {
var startingTime = moment().hours(8).minutes(0);
$scope.timeslots = [];
for(var i=0; i < interval; i++){
$scope.intervals=60;
$scope.timeslots.push(startingTime.add($scope.intervals,'minute').format("h:mm"));
}
}
答案 0 :(得分:1)
您必须将timeslots
添加到field
范围属性中的每个fields
,然后您可以将当前field
传递给setTimeSlot
方法,如图所示,
<input type="text" ng-model="interval" ng-blur="setTimeSlots(interval, field)">
然后在setTimeSlots
中按下如下所示的时间段,
$scope.setTimeSlots = function(interval, field) {
var startingTime = moment().hours(8).minutes(0);
field.timeslots = [];
for (var i = 0; i < interval; i++) {
$scope.intervals = 60;
field.timeslots.push(startingTime.add($scope.intervals, 'minute').format("h:mm"));
}
}
工作plunkr here