In that case Iād probably recommend a nested route. As a rule of thumb anytime you have "nestedā views itās a good candidate for nested routes. In this case you have a nice separation of concerns too. The āparentā route is concerned with fetching and rendering a list of items in a table (in the below examples I chose āusersā). The āchildā route is responsible for receiving and rendering the details of one of the items in the parent route.
Approach 1 - nested routes
Your table could be in your index route, and then you have a ādetailā route.
Letās say your table was for displaying users. You could put something like this in your router:
Router.map(function() {
this.route('users', { path: '/users' }, function() { // the path param here is redundant, just wanted to be explicit
this.route('user', { path: '/:id' });
});
});
Then in your āusersā template and route you put everything pretty much just as you have it (just make sure you include an {{outlet}}
in the template to render the child view into) but instead of doing a transitionTo('otherroute');
simply change it to transitionTo('users.user', model);
and alternatively you could even use a link-to in the table instead of having the action and transitionTo (if it fits in your table of course).
Then in /templates/users/user.hbs
you put the content of the DIV that you want to display (the details of the āuserā in this case). There are a lot of advantages to this approach, especially if you want to link directly to the URL <your app server>/#/users/4
for example, you will have fewer headaches with the data getting fetched, selected and displayed correctly.
Approach 2 - one route, query param instead of dynamic segment param
That said, you could continue the way you intended, where you just have one route and template, and when you select a table row it renders the details in the same template in the div. In that case you could add a second model to your route like so:
...
queryParams: {
parameter: {
refreshModel: true,
}
},
model: function(params){
return Ember.RSVP.hash({
users: this.store.findRecord("user", params.id)
selectedUser: this.store.peekRecord("user", params.parameter)
});
},
...
Then in your template you could render the contents of model.selectedUser
in our div. Since we set up āparameterā to refresh the model every time you click a new table row the peekRecord will update to that new model. And since you can only select models from the table it means youāre guaranteed to have the record already (enabling you to user peekRecord). Of course you could also use findRecord, it would probably be redundant server work.
Your controller should already be set up correctly if you got the first example working, so then youād be all set.