简体   繁体   中英

AngularJS ng-repeat nested JSON data

I have a manga reading website and I trying to rebuild with AngularJS.

Here is JSON Data:

[
  {
    "name": "Bleach",
    "random": [
        {
            "chapter": "787",
            "Paths": [
                "path/to/1.jpg",
                "path/to/2.jpg",
                "path/to/3.jpg"
            ]
        },
        {
            "chapter": "788",
            "Paths": [
                "path/to/1.jpg",
                "path/to/2.jpg",
                "path/to/3.jpg"
            ]
        }
    ]
  },
  {
    "name": "Naruto",
    "random": [
        {
            "chapter": "332",
            "Paths": [
                "path/to/1.jpg",
                "path/to/2.jpg",
                "path/to/3.jpg"
            ]
        },
        {
            "chapter": "333",
            "Paths": [
                "path/to/1.jpg",
                "path/to/2.jpg",
                "path/to/3.jpg"
            ]
        }
    ]
  }
]

I want to display these images sequentially. Like this . But in this current code nothing displayed.

Related oku.html part:

<img ng-repeat="bilgi in bilgiler.random" ng-src="http://localhost/{{bilgi.paths}}">

App.js:

$stateProvider
.state('oku', {
url: "/oku/:name/:id",
views: {
"viewC": { templateUrl: "oku.html",
            controller: "nbgCtrl",},
},
   resolve: {
     alData : function(NBG, $stateParams, $filter){
        return NBG.adlar.then(function(res){
            return $filter('filter')(res.data, {chapter: $stateParams.id}, true)[0];
        });
     }
   }
 })

.controller('nbgCtrl', function($scope, alData, NBG) {
$scope.images = alData;
NBG.adlar.success(function(verHemen){
   $scope.bilgiler = verHemen;
})
})

You need to use some form of wrapper for your repeat. For example:

<div ng-repeat="bilgi in bilgiler.random">
   <img ng-src="{{bilgi.Paths}}" />
</div>

You can also use span, li tags etc. More data on ng-repeats can be found here: https://docs.angularjs.org/api/ng/directive/ngRepeat

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM