jeudi 25 décembre 2014

ember different controller for a property

I have a session and a test. Session holds many tests - so in the model it is a DS.HasMany.


The view has a tests table, and I want it to be sortable. So the question is - how can I define a tests controller to the tests "property" in session


session.hbs:



<div class="main-container">
<h1>session {{id}}</h1>

<table class="tests-table table table-bordered">
<tr>
<th>ID</th>
<th>Logical ID</th>
<th>name</th>
</tr>
{{#each test in tests}}
<tr>
<td>{{test.id}}</td>
<td>{{test.logicalId}}</td>
<td>{{test.name}}</td>
</tr>
{{/each}}
</table>
</div>


routes/session.js:



import Ember from 'ember';

export default Ember.Route.extend({
model: function(params) {
return Ember.RSVP.hash({
session: this.get('store').find('session', params.session_id),
tests: this.get('store').find('test', {
session_id: params.session_id
})
});
},

setupController: function(controller, model) {
controller.set('model', model.session);
var testsController = this.controllerFor('tests');
testsController.set('model', model.tests);
}
});




Aucun commentaire:

Enregistrer un commentaire