dimanche 4 janvier 2015

Ember routes not loaded in order

I'm having an issue where the beforeModel (or afterModel) on my route isn't called after the application controller has been setup. This is an issue because I need some data from the application controller.


In another route this works as I'd expect (that the application controller is loaded prior to the route). The only difference is the one that works is an Ember.ArrayController and the one that doesn't is a standard Ember.Controller. I'm using beforeModel even though there isn't a model simply because I'm trying to transition away from it if a condition isn't meet.


If I change my non-working controller to an Ember.ArrayController and put in a pointless model call in the router then it still doesn't work.


The only other difference I can think of is that the one that isn't working is a nested controller defined by just a route and the working one isn't nested and is defined by resource.



Router.map(function() {

this.resource("wizard", function() {
this.resource("wizard/schools", {path: "/schools"}, function() {
this.route("new"); // This one doesn't work
});
});

...

this.resource("budgets", { path: "/schools" }); // This one does work
});


Any idea how I can ensure the application route/controller is loaded prior to my route?


I'm trying to do something along the lines of:



beforeModel: function() {
var customerAccountPromise = this.controllerFor('application').get('customerAccount');
var self = this;
return customerAccountPromise.then(function(customerAccount) {
return self.get('store').find('school').then(function(schools) {
if (customerAccount.get('schoolLimit') <= schools.get('length')){
self.transitionTo('school', schools.get('firstObject'));
}
});
});
},


I'm currently running:



DEBUG: Ember : 1.8.1
DEBUG: Ember Data : 1.0.0-beta.12
DEBUG: Handlebars : 1.3.0
DEBUG: jQuery : 1.11.1




Aucun commentaire:

Enregistrer un commentaire