We've used the PhotoView
class twice now; it creates a link, as you might recall, to an individual page for each photo. Let's create that page next. This time, we'll start in the router. First, add this route to the routes
property:
'photo/:id': 'showPhoto',
Then, here's the showPhoto
method is partners with:
showPhoto: function (id) { var thiz = this, photo = new Photo({ id : parseInt(id, 10) }); photo.fetch().then(function () { var comments = new Comments({ photo: photo }), var photoView = new PhotoPageView({ model: photo, collection: comments }); comments.fetch().then(function () { thiz.main.html(thiz.navView.render().el); thiz.main.append(photoView.render().el); }); }); },
Just as we did with the showUser
function, we get the photo data by creating a Photo
instance with id
, and then calling the fetch
method. However, we're also creating a Comments
collection based on this photo...