I am writing a Backbone application where a user can search for video games.
The following piece of code gives back a random game that a user typed in using a searchfield. For example, if a user searches for Mario, it lists one of the top 5 five Mario games from the API.
$.getJSON(url, function(data){
var games = data.results
var game = games[Math.floor(Math.random() * 5)];
var content = self.game_template({game: game});
self.$el.append(content);
$('.main-game').css("display", "block");
});
I would like that when a user searches for a particular title, that it renders every game. So when a user searches for Mario, all the Mario games render. The games are inside an array, so if I say, var game = games;
, the Chrome inspector gives back Object, which contains a lot of other objects which are the games.