I am reading this very interesting article about knockoutJs ( http://wildermuth.com/2011/11/20/Using_MVVM_on_the_Web_with_KnockoutJS )
And I came across this jquery call:
$.each(response.results, function (x, game) {
theViewModel.games.push(new gameModel()
.id(game.Id)
.name(game.Name)
.releaseDate(game.ReleaseDate)
.price(game.Price)
.imageUrl(game.ImageUrl)
.genre(game.Genre));
});
what I don’ t understand is the function (x, game), the x is the index isn’ t ?, how about the ‘game’ argument, where is it coming from ?
The callback you supply to
$.eachwill be called once for eaach result inresponse.results. When it calls the callback it will pas in the index and the result.For example, it does this (illustrative example)