vendredi 27 octobre 2017

Ember.js - Learning dynamic segments, link-to, nested routes

I'm trying to learn how to do dynamic segments in Ember. I thought I understood but obviously it's not working. Are my corresponding file structure and model queries correct?

router.js

Router.map(function() {
  this.route('photos', function() {
    this.route('photo', { path: '/:photo_id' }, function() {
      this.route('comments');
      this.route('comment', { path: '/comments/:comment_id' });
    });
  });
});

Creating dynamic link list somewhere in the app using the photos model:


  


Does everything line up with my file stucture?

File structure:

app
├── controllers
|   └── photo
|   |   └── comment
|   |   |   └── index.js
|   |   ├── index.js
|   |   └── comments.js
|   └── photos.js
├── routes
|   └── photo
|   |   └── comment
|   |   |   └── index.js
|   |   ├── index.js
|   |   └── comments.js
|   └── photos.js
└── templates
|   └── photo
|   |   └── comment
|   |   |   └── index.hbs
|   |   ├── index.hbs
|   |   └── comments.hbs
|   └── photos.hbs
└── router.js

routes/photos.js

model() {
  return this.store.findAll('photo');
}

Lets say I want to display all the photos with comments, I can get the model below.

routes/photo/index.js

model(params) {
  return this.store.findRecord('photo', params.photo_id, {include: 'comments'});
}

Unsure about the next 2 models.

routes/photo/comments.js

model(params) {
  return this.store.query('comment', { photo: photo_id })
}

routes/photo/comment/index.js

model(params) {
  return this.store.findRecord('comment', params.comment_id);
}




Aucun commentaire:

Enregistrer un commentaire