【发布时间】:2016-12-11 08:15:37
【问题描述】:
我有一个表单,用户需要在其中选择两周的轮班类型。我需要做的是为每个单元格设置 UNIQUE 默认值,例如Day 1: D, Day2:N, etc.。我怎样才能做到这一点?
【问题讨论】:
标签: angularjs select ng-repeat
我有一个表单,用户需要在其中选择两周的轮班类型。我需要做的是为每个单元格设置 UNIQUE 默认值,例如Day 1: D, Day2:N, etc.。我怎样才能做到这一点?
【问题讨论】:
标签: angularjs select ng-repeat
您可以使用此代码:
<select ng-model="day.selectedShiftType" ng-options="shift as shift.strId for shift in shifts" ng-init="day.selectedShiftType = shifts[0]">
上面将始终选择第一个选项,但我们可以使用以下代码使其随机:
$scope.GetRandomIndex = function() {
return Math.floor((Math.random()*3)+1);
}
html代码:
<select ng-model="day.selectedShiftType" ng-options="shift as shift.strId for shift in shifts" ng-init="day.selectedShiftType = shifts[GetRandomIndex()]">
【讨论】:
$scope.GetRandomIndex = function(){ return Math.floor((Math.random()*3)+1); }, 和 html 代码:<select ng-model="day.selectedShiftType" ng-options="shift as shift.strId for shift in shifts" ng-init="day.selectedShiftType = shifts[GetRandomIndex()]">