[英]Using ng-repeat on a JSON object doesn't work - why?
I can't seem to iterate over a JSON object using ng-repeat. 我似乎无法使用ng-repeat遍历JSON对象。 I did test it directly by index and it works, but just can't seem to loop and print.
我确实通过索引直接对其进行了测试,并且可以正常工作,但似乎无法循环和打印。 What am I doing wrong?
我究竟做错了什么? JSFiddle link .
JSFiddle链接 。
Here's my code: 这是我的代码:
<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>
The script: 剧本:
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;
});
});
That's because you iterate over the whole data returned by the calendar query, and not over the entries themselves. 这是因为您要遍历日历查询返回的全部数据,而不是遍历条目本身。 Change your
ul
to: 将您的
ul
更改为:
<ul ng-repeat="entry in events.feed.entry">
<li>{{ entry.title.$t }}</li>
</ul>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.