0

現在のコードでは、データを取得するためにダミーの方法を使用しています。そのような

var controlMeetings = $.ajax({
        type: "GET",
        url: "./Info.xml",
        contentType: "text/xml",
        dataType: "xml",
        success: function (dataSource) {           

            controlMeetings = PureJson(dataSource);         
        }
});

function MeetingsCtrl( $scope, $compile ) {

  $scope.meetings = controlMeetings;  
  $('#div1').html(
       $compile(
         '<ul><li ng-repeat="meeting in meetings"><a>{{meeting.count}}</a> <ul><li ng-repeat="child in meeting.children">{{child.meet}}</li></ul></li></ul>'
       )($scope)
     );
  $('#div1').prepend('<div class="mHeader">Race cources</div>');


}

明らかに良くありません(はい、このコードを恥じています)が、動作するatmです。問題は、コントローラー内に $cope.meetings 変数を実際に入力し、グローバル変数の使用を回避する方法です。

4

1 に答える 1

1

AngularJS メソッドを使用して例を書き直そうとしました。

コントローラ:

function MeetingsCtrl ($scope) {

  $http.get('./Info.xml').success(function (data) {
      $scope.meetings = data;
    });

}

ファイルを閲覧する:

<div id="div1">
  <div class="mHeader">Race cources</div>
  <ul>
    <li ng-repeat="meeting in meetings">
      <a>{{meeting.count}}</a>
        <ul><li ng-repeat="child in meeting.children">{{child.meet}}</li></ul>
    </li>
  </ul>
</div>
于 2013-04-30T08:57:07.367 に答える