在 JSON 对象上使用 ng-repeat 不起作用 - 为什么?
Using ng-repeat on a JSON object doesn't work - why?
我似乎无法使用 ng-repeat 遍历 JSON 对象。我确实通过索引直接测试了它并且它有效,但似乎无法循环和打印。我究竟做错了什么? JSFiddle link.
这是我的代码:
<div ng-app="myApp">
<div ng-controller="Ctrl">
<h3>Upcoming Events</h3>
<ul ng-repeat="event in events">
<li>{{ event.feed.entry.title.$t }}</li>
</ul>
<!-- testing single entry here - it works! -->
<small>{{ events.feed.entry[0].title.$t }}</small>
</div>
</div>
脚本:
var app = angular.module('myApp', []);
var feedUrl = 'https://www.google.com/calendar/feeds/ogmda.com_89pas0l9jbhpf053atd83hdj30%40group.calendar.google.com/public/basic?alt=json';
app.controller('Ctrl', function($http, $scope) {
$http.get(feedUrl).success(function(data) {
$scope.events = data;
});
});
那是因为您迭代了日历查询返回的全部数据,而不是条目本身。将您的 ul
更改为:
<ul ng-repeat="entry in events.feed.entry">
<li>{{ entry.title.$t }}</li>
</ul>
我似乎无法使用 ng-repeat 遍历 JSON 对象。我确实通过索引直接测试了它并且它有效,但似乎无法循环和打印。我究竟做错了什么? JSFiddle link.
这是我的代码:
<div ng-app="myApp">
<div ng-controller="Ctrl">
<h3>Upcoming Events</h3>
<ul ng-repeat="event in events">
<li>{{ event.feed.entry.title.$t }}</li>
</ul>
<!-- testing single entry here - it works! -->
<small>{{ events.feed.entry[0].title.$t }}</small>
</div>
</div>
脚本:
var app = angular.module('myApp', []);
var feedUrl = 'https://www.google.com/calendar/feeds/ogmda.com_89pas0l9jbhpf053atd83hdj30%40group.calendar.google.com/public/basic?alt=json';
app.controller('Ctrl', function($http, $scope) {
$http.get(feedUrl).success(function(data) {
$scope.events = data;
});
});
那是因为您迭代了日历查询返回的全部数据,而不是条目本身。将您的 ul
更改为:
<ul ng-repeat="entry in events.feed.entry">
<li>{{ entry.title.$t }}</li>
</ul>