我目前正在开发一个使用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"><</a>
<a href="#/details/{{nextItem}}" class="btn btn-left">></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">« Back to search</a>
</section>
我想在data.course [ 4 ]中从所选课程的按钮中获取动态ID而不是上面的静态。讲座
JSON:
那我该怎么做呢? 演示:www.faizansaiyed.ml/EduvanceApp
答案 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:</b> {{item.type}}</p>
</div>