javascript - AngularJS ng-重复嵌套 JSON 数据

标签 javascript json angularjs angularjs-ng-repeat

我有一个漫画阅读网站,我尝试用 AngularJS 重建。

这是 JSON 数据:

[
  {
    "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"
            ]
        }
    ]
  }
]

我想按顺序显示这些图像。 Like this 。但在当前代码中没有显示任何内容。

相关oku.html部分:

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

应用程序.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;
})
})

最佳答案

您需要使用某种形式的包装器来进行重复。例如:

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

您还可以使用 span、li 标签等。有关 ng-repeats 的更多数据可以在此处找到:https://docs.angularjs.org/api/ng/directive/ngRepeat

关于javascript - AngularJS ng-重复嵌套 JSON 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32954478/

相关文章:

javascript - 列出未使用 .val 函数显示的字段内容

javascript - 单击图像后如何创建下拉菜单? [ Bootstrap/Angular ]

java - 从 Jersey 1.* 升级到 Jersey 2.5

javascript - 从 JS 客户端在 SignalR 控制台应用程序上进行身份验证

javascript - 为什么在 Angular 中通过 $parse 分配设置值时不触发scope.$watch?

javascript - 将 radio 设置为未选中

javascript - chop 字符串以保留前 n 个单词

javascript - GPL 许可证如何限制商业 Web 应用程序?

javascript - jQuery.parseJSON 中的语法错误

c# - 如何检查动态是否为空。