javascript - Ember 'needs' property doesn't work unless you visit the needed controllers route first -
i've come across either issue ember's 'needs' controller property or don't understand proper way achieve goal.
the goal able have access 1 or more controller's content controller.
so example have route accounts need have access contents of bank accounts , credit accounts may display accounts :)
the problem content alway empty controllers unless visit bank , credit account routes first!
here's jsbin illustrating problem:
a controller has it's model automatically populated when visit route needing it. controllers can exist without models. needs
should happen upstream, not sibling resources/routes.
if resource depends on another, should part of nesting structure, or fetched @ same time.
this.resource('accounts', function(){ this.resource('bank-accounts'); ..... });
generally in use case don't want nested route, want multiple resources return multiple resources single route, or setup multiple controllers in setupcontroller
hook.
model multiple models (properties)
app.fooroute = em.route.extend({ model: function(){ return em.rsvp.hash({ cars: this.store.find('car'), dogs: this.store.find('dog') }); } });
using above technique controller objectcontroller 2 properties, cars
, dogs
each of collection.
setupcontroller set multiple models
app.fooroute = em.route.extend({ model: function(){ return this.store.find('car'); }, setupcontroller: function(controller, model){ // this._super default implementation of setupcontroller this._super(controller, model); this.controllerfor('dogs').set('model', this.store.find('dog')); } });
or can in-between, mixing , matching.
Comments
Post a Comment