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 = course; $scope.courses である必要があります。

HTML では: {{course.Nome}} {{course.Name}} ではないでしょうか?

その上にスペイン語 (?) が表示されますが、それ以外の場所では .Name と言うので、一貫性を保つのが最善ですよね?

そうは言っても、各関数で json URL からロードしているように見えるように、外部の json データ ストアから $scope にオブジェクトをロードしても問題ないようです。あなたの投稿へのコメント投稿者は、これを認識していないようでしたか? このデータを $scope に永続的に保存しようとしていると彼らは信じていると思いますか? 多分私はそれらが何かを見ていない...しかし、データモデルオブジェクトをいつか$scope.somethingに追加しないと、{{something}}は単に機能せず、{{something.elseも機能しません}}。

私はここで基地から離れていますか?

于 2013-01-08T19:22:48.910 に答える