lundi 23 mars 2015

Sorting parent's model the ember way

in a simple, standard ember.js route ...



this.resource('foo', function () {
this.route('show');
this.route('new');
});


... I have a foo template that shows a new button (link to foo/new route) and the foo.bar data of the foo objects (with links to foo/show in a sorted way using the foo controller ...



import Ember from 'ember';
export default Ember.Controller.extend({
sortProperties: [ 'bar:desc' ],
sortedList: Ember.computed.sort('model', 'sortProperties')
});


The routes foo/show and foo/new do the obvious, nothing special.


I don't need or want a "real" foo/index route, since all my navigation needs are catered for in the foo route and template. Therefore I want to transitionTo from foo/index whenever I enter that route to the first (as in given by the sorting above) foo/show route (or foo\new if there is nothing to show).


I've learned that "the ember way" is to transitionTo out of the route, but never ever out of the controller.


Now, my problem is, that I get access to the unsorted data very easily (it's the model of my parent route, that I can access via modelFor) and I can sort this "manually", but I'd rather use the already sorted data from my parent's controller. Now, I'm at a bit of a loss which hook to use in the route to be sure that my parent route's controller's computed properties are ready - and it doesn't feel right. So, what would be the ember way to do this?





Aucun commentaire:

Enregistrer un commentaire