从嵌套的JSON中回收数据并使用AngularJS显示列表

时间:2016-05-07 11:32:43

标签: javascript angularjs json

我目前正在开发一个使用AngularJS和JSON数据的应用程序并且陷入困境。我也是Angular的新手。这是:

控制器代码段:

std::vector

视图是:( Details.html)

courseController.controller('LectureController', ['$scope', '$http', function($scope, $http){

    $http.get('js/data.json').success(function(data){

        $scope.lecture = **data.course[4].lectures**;

        $scope.lectureOrder = 'videoId';
    });
}]);

(Lectures.html)

<section class="artistinfo">
  <div class="artist cf" ng-model="courses">
    <div align="right"><a href="#/details/{{prevItem}}" class="btn btn-left">&lt;</a>
    <a href="#/details/{{nextItem}}" class="btn btn-left">&gt;</a></div>
    <img ng-src="{{courses[whichItem].thumbnail}}" alt="Photo of {{courses[whichItem].name}}">
    <h1>{{courses[whichItem].name}}</h1>
    <div class="info">
      <h3>{{courses[whichItem].description}}</h3>

      <div align="right">Lectures: {{courses[whichItem].lectures.length}}</div>
      <div align="center">
        <a href="#/lectures/{{courses[whichItem].courseId}}">
          <button>Get Started</button></div>
        </a>
    </div>
  </div>
  <a href="index.html">&laquo; Back to search</a>
</section>

我想在data.course [ 4 ]中从所选课程的按钮中获取动态ID而不是上面的静态。讲座

JSON:

JSON Structure Image

那我该怎么做呢? 演示:www.faizansaiyed.ml/EduvanceApp

1 个答案:

答案 0 :(得分:0)

我想你会做那样的事情:

$http.get('js/data.json').success(function(data) {
    $scope.records = data;
    $scope.whichItem = $routeParams.itemId;

在您的html文件中,您将这样做:

第一个html文件

<a href="#details/{{records.indexOf(item)}}" >

对于第二个html文件,您将这样做: 例如:

<div class="col s12 error_info_box" ng-repeat="item in records[whichItem].errors">

      <p><b>Error Type&#58;</b>&nbsp;&nbsp;{{item.type}}</p>






      </div>