HTML and CSS Reference
In-Depth Information
...
this.list = function(){
// Get the favorites from local storage
var _favorites = JSON.parse(localStorage.favorites),
// Create an empty movies variable
_movies = [],
// Get the favoritesList card from the DOM
_favoriteslist = document.getElementById('card-favorite_list');
}
...
}
You can see from the code, that you also created an empty movies array. This
will be used to hold all of the movie models created from the user's favorites
further into the code. You'll also get the favorite card list DOM element.
The next thing to do is to loop through each of the favorites retrieved from
localStorage . The for loop might look a little strange, as you are subtracting a
value of one from the iterator each time the for loop is run. This essentially
reverses the array, so that the last/most recent element is looped over first.
var app = app || {};
app.controller = app.controller || {};
app.controller.favorites = function(){
...
this.list = function(){
...
/**
* Loop through each of the favorites backward
* to ensure that the most recent favorite
* is displayed at the top of the list
*/
for(var i = _favorites.length; i > 0; i--){
var _favorite = _favorites[i - 1];
// Push the movie model to the movies array
_movies.push(new app.model.movie(unescape(_favorite.title),
_favorite.id, _favorite.posterframe, unescape(_favorite.synopsis)))
}
...
}
...
}
 
Search WWH ::




Custom Search