在我目前的代码中,我使用虚拟方式来获取数据。就像
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变量并避免使用全局变量?
答案 0 :(得分: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>