After completely rebuilding my website (which was originally hacked together with Wordpress), I decided to utilize Laravel and AngularJS. The transition has been quite challenging, but I'm almost there, except for one issue.
On my website, I have 'schemes' (or courses) that consist of 'units', which in turn contain 'lessons'. Retrieving this data using Eloquent has been smooth, and I am able to retrieve valid JSON in the following example structure...
[
{
"id": "1",
"title": "Sports",
"description": "This is a Sports course!",
"units": [
{
"id": "1",
"title": "Tennis",
"lessons": [
{
"id": "6",
"title": "Serving"
},
{
"id": "7",
"title": "Hitting the ball with top-spin"
}
]
},
{
"id": "2",
"title": "Athletics",
"lessons": [
{
"id": "1",
"title": "Long Jump"
},
{
"id": "2",
"title": "Hurdling Technique"
}
]
},
{
"id": "4",
"title": "Golf",
"lessons": [
{
"id": "4",
"title": "Pitching"
},
{
"id": "5",
"title": "Putting"
}
]
}
]
}
....
]
Additionally, I have a simple array that contains completed lesson ids for a specific user...
[2, 6, 8, 9]
Within my view, I am using nested ng-repeat loops as shown below...
...
<div ng-controller="SchemesController">
<div ng-repeat="scheme in schemes">
<h1>{{scheme.title}}</h1>
<div ng-repeat="unit in scheme.units">
<h3>{{unit.title}}</h3>
<div ng-repeat="lesson in unit.lessons">
<div>{{lesson.title}}: {{status}}</div>
</div>
</div>
</div>
</div><!--[end of ng-controller="SchemesController"]-->
....
The SchemesController is quite simple and looks like this...
var app = angular.module('schemesApp', []);
app.controller('SchemesController', function($scope){
$scope.schemes=jsonData;
});
The challenge I'm facing is populating the {{status}} field to indicate 'Complete' or 'Incomplete'. I have tried modifying the original array but didn't make much progress. I even explored using underscore.js but still couldn't figure it out.
Is there a way to achieve this, possibly by using underscore.js or by creating and calling a JavaScript function?
Any assistance or guidance on this matter would be greatly appreciated. As a school teacher, I find programming and web design to be a fun use of my spare time, so I apologize if my question seems trivial. Thank you in advance!
By the way, if anyone has a better 'title' suggestion for this question, please feel free to share.