[英]Using ng-repeat on a JSON object doesn't work - why?
我似乎無法使用ng-repeat遍歷JSON對象。 我確實通過索引直接對其進行了測試,並且可以正常工作,但似乎無法循環和打印。 我究竟做錯了什么? JSFiddle鏈接 。
這是我的代碼:
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.