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>');


}

它显然不好(是的,我为这段代码感到羞耻),但它的工作原理。问题是如何在控制器内准确填充 $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 回答