jeudi 11 juin 2015

Master Detail relationship with two related models in emberjs

I have two models, Videos belong to a category. A category has many videos. I have a list of categories on my home route. When you click on one of the categories you are transitioned to the category route which displays a list of categories on the left in the categories.hbs and the videos for that category in category.hbs So the categories route is the master and category is the detail.

Here is my current router:

export default Router.map(function() {
  this.resource('home', { path: '/' }, function() {
  });

  this.resource('categories', { path: 'categories' }, function() {
    this.resource('category', { path: ':category_id' });
  });

  this.resource('videos', { path: 'videos' }, function() {
    this.resource('video', { path: ':video_id' });
  });

});

Here are the routes

categories.js

export default Ember.Route.extend({
    model: function() {
        return this.store.find('category');
    }
});

category.js

export default Ember.Route.extend({
    model: function(params) {
    return this.store.find('category', params.category_id);
  }
});

How do I set this up so that when you click on a category from the home page the first video in that category is displayed, and the other videos in the category are displayed in the sidebar, so that when you click on one of them it becomes the detail and the other videos in that category become the master?

So to clarify.. What I have now is list of categories is the master, all videos in selected category are the detail. What I need is all videos in category are the master, and first video in category OR selected video are the detail.

Aucun commentaire:

Enregistrer un commentaire