问题描述:
我浏览了与此方案相关的帖子上的堆栈溢出。但是,我无法找到解决方案,因为这种情况非常具体。这就是为什么我发布这个问题的原因。
我是angularjs的完全新手。任何帮助将不胜感激。提前谢谢!
CalculateResult.html:
<tr ng-repeat="x in subjects">
<td ng-if="x.subjectCode.indexOf('ELECTIVE') == -1">{{ x.subjectCode }}</td>
<td ng-if="x.subjectName.indexOf('ELECTIVE') == -1">{{ x.subjectName }}</td>
<td ng-if="x.subjectCode.indexOf('ELECTIVE') != -1">{{ elective.electiveSubjectCode }}</td>
<td ng-if="x.subjectName.indexOf('ELECTIVE') != -1" ng-model="elective" ng-init="increment()">
<select class="form-control" ng-init="elective = electives[index][0]" ng-model="elective" ng-options="elective.electiveSubjectName for elective in electives[{{index}}]" ng-change="changeSelectedItem(elective.electiveSubjectCode,elective.electiveCredit)" required>
</select>
</td>
</tr>
CalculateResult.js:
var app=angular.module('myApp',[]);
app.controller('myCtrl',function($scope,$http,$window){
$scope.title = sessionStorage.getItem('title');
var length = sessionStorage.getItem('length');
$scope.subjects = [];
for(var i=0;i<length;i++)
{
$scope.subjects.push({subjectCode:sessionStorage.getItem('subjectCode'+i),subjectName:sessionStorage.getItem('subjectName'+i),credit:sessionStorage.getItem ('credit'+i)});
}
$scope.noOfElectives = sessionStorage.getItem('noOfElectives');
$scope.electives = [];
$scope.electiveArray = [];
$scope.elective = {};
for(var i=1;i<=$scope.noOfElectives;i++)
{
$scope.electiveArray = [];
for(var j=1;j<=sessionStorage.getItem('electiveLength'+i);j++)
{
$scope.elective = {electiveSubjectCode:sessionStorage.getItem('electiveSubjectCode'+i+j),electiveSubjectName:sessionStorage.getItem('electiveSubjectName'+i+j),electiveCredit:sessionStorage.getItem('electiveCredit'+i+j)};
$scope.electiveArray.push($scope.elective);
}
$scope.electives.push($scope.electiveArray);
}
$scope.elective.electiveSubjectCode = '--';
$scope.elective.electiveCredit = '--';
$scope.index = -1;
$scope.increment=function(){
$scope.index = $scope.index + 1;
}
$scope.changeSelectedItem=function(electiveSubjectCode,electiveCredit){
$scope.elective.electiveSubjectCode = electiveSubjectCode;
$scope.elective.electiveCredit = electiveCredit;
}});