在我当前的代码中,我使用虚拟方式来获取数据。就像是
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 变量并避免使用全局变量?