The Trucks model is backed by a db, and accessible via a rest api. The Analysis model, however, is NOT backed by a db but is simply used for computations on the client side.
I need to access the Trucks array from within the Analyses controller, but I encounter 2 problems
Trucks data needs to be retrieved from the database. If I visit the
/analyses
route immediately then there are no Trucks in the data store when checking the ember console. However, if I visit/trucks
first then I notice 6 records are retrieved and in the data store.Inside the
AnalysesController
I have specified the dependency on Trucks but I am unable to access the data from within the controller. http://emberjs.com/guides/controllers/dependencies-between-controllers/ shows how to access from within a template.
Below is the code
// router.js
Classmove.Router.map(function() {
this.resource('trucks');
return this.resource('analyses');
});
Classmove.TrucksRoute = Ember.Route.extend({
model: function() {
return this.store.find('truck');
}
});
Classmove.Analyses = Ember.Route.extend({
model: function() {
return this.store.find('analysis');
}
});
// analyses_controller.js
Classmove.AnalysesController = Ember.ArrayController.extend({
needs: ['trucks'],
trucks: Ember.computed.alias('controllers.trucks'),
isCalculating: false,
checkTrucks: function() {
// I want to access the trucks here
// I found that I was able to access it like so
this.get('trucks').model.content
// but shouldn't there be a direct way without bypassing Ember
},
actions: {
calculate: function() {
// does stuff - removed from example for simplicity
}
}
});