AngularJS - 嵌套forEach迭代Json

时间:2015-06-06 22:30:23

标签: json angularjs loops foreach

我正在尝试打印所有系列的所有名称和书籍。所以我使用了2个forEach循环,但书籍信息在控制台上显示为未定义。你能告诉我如何解决它吗?

数据:

var data = {
    "records": [
        {
            "name": "Spectrum Series",
            "seriesid": "SpectrumSeries",
            "book": [
                {
                    "name": "White Curse",
                    "bookid": "WhiteCurse",
                    "image": "book1"                    
                },
                {
                    "name": "Blue Fox",
                    "bookid": "BlueFox",
                    "image": "book2"                   
                }
            ]
        }

    … other series
 ]
};

角度循环:

    $scope.serieslist = data.records;
   angular.forEach($scope.serieslist, function(series){
       console.log(series.name);
       angular.forEach(series, function(book){
           console.log(book.name);
       });         
   });  
});

1 个答案:

答案 0 :(得分:2)

angular.forEach(series, function(book){

必须是

angular.forEach(series.book, function(book){