将学生缺勤添加到一系列学生缺勤ID中

时间:2014-06-14 22:47:52

标签: javascript arrays angularjs

我正在尝试在包含每个学生ID的数组中添加学生缺席 其中studentList在代码中是学生和学生的数组,如果其= true,则学生有一个名为isAbsence的属性,那么必须将学生if添加到ids数组中,否则不会添加 问题是:
即使我检查学生盒,似乎ids的数组总是空的!所以没有学生缺席!!!“

这里是html

<form name="absenceForm"  novalidate>

    <table id="studentListTable" border="1">
        <thead>
            <tr>
                <th>Absent?</th>
                <th>Student ID</th>
                <th>Student Name</th>
            </tr>
        </thead>
        <tbody>

            <tr ng-repeat="student in studentsList">
                <td><input type="checkbox" ng-model="student.isAbsenct"               
                  value="student.isAbsent" ng-class="student.isAbsent ? 'checked' : ' '"></td>
                <td>{{student.id}}</td>
                <td>{{student.firstName}} {{student.lastName}}</td>
            </tr>

        </tbody>
    </table>
    <br> <input type="submit" value="Submit" ng-click="addAbsence()"/>
</form>

并在controller.js

 $scope.addAbsence = function() {
con
        $scope.absentStudentIds = [];
        for (var i = 0; i < $scope.studentsList.length; i++)
        {
            if ($scope.studentsList[i].isAbsent === true)
            {
                $scope.absentStudentIds.push($scope.studentsList[i].id);
                console.log($scope.absentStudentIds);
            }
        }
        var requestParameters = {
            crn: $scope.selectedCrn,
            absenceDate: $scope.selectedAbsenceDate,
            absentStudentIds : $scope.absentStudentIds

        };

        $http.post('http://localhost:8080/amsjs/rs/users/absence', requestParameters)
                .success(function(response) {
                    console.log(response);
                    $scope.$parent.alertMessage = response;

                })
                .error(function(response, status, headers, config) {
                    $scope.$parent.alertMessage = response;
                    console.log(response, status, config);

                });
    };


提前致谢

1 个答案:

答案 0 :(得分:0)

有一个错字。在ng-model中,您可以参考&#34; student.isAbsenct&#34;而不是&#34; student.isAbsent&#34;。