0
<ul>
<li ng-repeat="comic in comiclist">
<span>{{ comic.title }} : {{comic.id}}</span>
<div >
<img ng-src="{{comic.thumbnail.path}}.{{comic.thumbnail.extension}}"/>
</div>
<div>
<ul>
<li ng-repeat="character in charlist + {{comic.id}}">
<span>{{character.name}}</span>
</li>
</ul>
</div>
</li>
</ul>
JS與角
var App = angular.module('MarvelApp', []);
App.controller('MainController', function($scope,$window, $http) {
$scope.GetSeries = function(){
$http.get('http://gateway.marvel.com/v1/public/series?')
.then(function(response){
$scope.serieslist = response.data.data.results;
});
};
$scope.GetComics = function(){
$http.get('http://gateway.marvel.com/v1/public/series/' + $scope.selectedseries + '/comics?')
.then(function(response){
$scope.comiclist = response.data.data.results;
});
//comic in comiclist contains comic.id
//which needs to go to GetCharacter()
}
$scope.GetCharacter = function(comicid){
$http.get('http://gateway.marvel.com/v1/public/comics/' + comicid + '/characters')
.then(function(response){
$scope.['charlist' + comicid] = response.data.data.results;
//this list needs to be displayed in the second ng-repeat
});
};
});
我想獲得字符列表中正確的div來顯示。我之前是如何設置它的(沒有$scope.['charlist' + comicid]
),它也覆蓋了其他的ng-repeats。
另外,無論何時調用GetComics()
,它都會自動執行。
「angular.js:13920 TypeError:Can not set property'60151'of undefined」 這是我現在得到的錯誤$ scope.charlist [comicid] = ...; 60151是漫畫 – KevHau
從技術上講,JavaScript沒有關聯數組。把它看作需要實例化的(數組)對象。添加行「$ scope.charlist = [];」在你的控制器的頂部。然後稍後引用$ scope.charlist [comicid] = ....應該可以工作。 – Paurian
那工作:)謝謝! – KevHau