0

伙计们。我正在尝试调用一些 AJAX Post trhu AngularJS,并且我想从我的 $scope 变量中发送所有属性。我有这个表格:

<div ng-controller="DiscountPrintsCtrl">

    <div>
    Choose the year:
    <select ng-model="selectedYear" ng-change="searchCourses()">
        <option ng-repeat="year in years" value="{{year.ID}}">{{year.Name}}</option>
    </select>
</div>

<div>
    Choose the course:
    <select ng-model="selectedCourse" ng-change="searchStudents()">
        <option ng-repeat="course in courses" value="{{course.ID}}">{{course.Nome}}</option>
    </select>
</div>

<div>
    Choose the student:
    <select ng-model="selectedStudent" ng-change="searchStudentDetails()">
        <option ng-repeat="student in students" value="{{student.ID}}">{{student.Name}}</option>
    </select>
</div>

<div ng-model="studentDetails">
    Details about the student:<br /><br />
    <label>Name: {{studentDetails.Name}}</label><br />
    <label>Number: {{studentDetails.Number}}</label><br />
    <label>Print quote: {{studentDetails.PrintQuote}}</label><br />
</div>

<div>
    <table>
        <thead><tr>
            <td></td>
            <td>Title</td>
            <td>Grade</td>
            <td>Summary</td>
            <td>Author</td>
            <td>Number of pages</td>
        </tr></thead>
        <tbody>
            <tr ng-repeat="publication in publications">
                <td><input type="checkbox" ng-model="publication.Selected" /></td>
                <td>{{publication.Title}}</td>
                <td>{{publication.Grade}}</td>
                <td>{{publication.Comments}}</td>
                <td>{{publication.Author}}</td>
                <td>{{publication.NumberOfPages}}</td>
            </tr>
        </tbody>
    </table>
</div>

<button ng-click="submitForm()" value="Confirm discounts" />

我有这个JS:

<script type="text/javascript">

function DiscountPrintsCtrl($scope, $http) {


    $http.get(url).success(function (years) {

        $scope.years = years;
        $scope.selectedYear = '';

    });

    $scope.searchCourses = function() {

        var url = '/json/GetCoursesFromYear?' + 
            'selectedYear=' + $scope.selectedYear;
        $http.get(url).success(function (courses) {
            $scope.course = courses;
            $scope.selectedCourse= '';
        });
    }

    $scope.searchAlunosAnoSemestre = function() {

        var url = '/json/GetStudentsFromCouse?' +
            'selectedCourse=' + $scope.selectedCourse;

        $http.get(url).success(function(students) {
            $scope.students = students;
            $scope.selectedStudent = '';
        });
    }

    $scope.searchStudentDetails = function() {

        var url = '';

        url = '/json/GetStudentDetails?' +
            'selectedStudent=' + $scope.selectedStudent;

        $http.get(url).success(function(studentDetails) {
            $scope.studentDetails= studentDetails;
        });

        url = '/json/GetPublicationsForStudent?' +
            'selectedStudent=' + $scope.selectedStudent;
        $http.get(url).success(function(publications) {
            $scope.publications = publications;
        });
    }

    $scope.submitForm = function () {
        // How to submit the entire $scope???
    }
}

任何的想法?关于我的 JS 代码的任何考虑?谢谢大家!!!

4

1 回答 1

1

你有错别字要修正,朋友:

在 .js 中:$scope.course = 课程;应该是 $scope.courses!

在 html 中: {{course.Nome}} 不应该是: {{course.Name}} 吗?

我在上面看到了一些西班牙语(?),但在其他任何地方你都说 .Name 所以最好保持一致,对吗?

也就是说,从外部 json 数据存储中将对象加载到 $scope 似乎很好,就像您在每个函数中所做的那样,从 json URL 加载。您帖子的评论者似乎没有意识到这一点?我认为他们认为您正在尝试将此数据永久存储在 $scope 中?也许我没有看到它们是什么......但如果你不将你的数据模型对象添加到 $scope.something 那么 {{something}} 根本不会工作,也不会 {{something.else }}。

我在这里离基地很远吗?

于 2013-01-08T19:22:48.910 回答