AngularJS - select 选项的 ng-repeat 默认值
AngularJS - ng-repeat default value for select option
我有一个表格,用户需要 select 两周的轮班类型。我需要做的是为每个单元格设置 UNIQUE 默认值,例如Day 1: D, Day2:N, etc.
。我怎样才能做到这一点?
您可以使用此代码:
<select ng-model="day.selectedShiftType" ng-options="shift as shift.strId for shift in shifts" ng-init="day.selectedShiftType = shifts[0]">
以上总是 select 第一个选项,但我们可以使用以下代码使其随机化:
$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()]">
我有一个表格,用户需要 select 两周的轮班类型。我需要做的是为每个单元格设置 UNIQUE 默认值,例如Day 1: D, Day2:N, etc.
。我怎样才能做到这一点?
您可以使用此代码:
<select ng-model="day.selectedShiftType" ng-options="shift as shift.strId for shift in shifts" ng-init="day.selectedShiftType = shifts[0]">
以上总是 select 第一个选项,但我们可以使用以下代码使其随机化:
$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()]">