gpt4 book ai didi

javascript - ng-repeat 只给我一个结果

转载 作者:行者123 更新时间:2023-11-28 13:22:37 25 4
gpt4 key购买 nike

我正在使用AngularJs阅读iTunes API 。我想获得 <entry> 中的所有结果但到目前为止我只得到第一个结果:

<div class="container" ng-controller="appController">
<div class="item" ng-repeat="chart in charts">
<h2>{{chart.entry[$index]['im:name'].label}}</h2>
</div>

结果是im:name来自entry[0] ;当我替换$index时有了一个数字,我也得到了结果,所以显然一切都加载得很好。

Controller :

app.controller('appController', ['$scope', 'charts', function($scope, charts) {
charts.success(function(data) {
$scope.charts = data;
});

}]);

加载 JSON 文件:

app.factory('charts', ['$http', function($http) {
return $http.get('https://itunes.apple.com/us/rss/topsongs/limit=100/json')
.success(function(data) {
return data;
})
.error(function(data) {
return data;
});
}]);

Json structure

最佳答案

我想你想重复charts.feed.entry。

<div class="item" ng-repeat="entry in charts.feed.entry">
<h2>{{entry['im:name'].label}}</h2>
</div>

编辑:解释为什么这是charts.feed.entry而不是charts.entry。来自问题:

<div class="item" ng-repeat="chart in charts">

这循环遍历图表,因为它是一个对象而不是数组,意味着循环遍历其属性。只有一个,因此有一次迭代,它将单一属性 feed 分配给图表。因此:

chart.entry[$index]['im:name'].label

相当于:

charts.feed.entry[$index]['im:name'].label

关于javascript - ng-repeat 只给我一个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31893264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com