Friday, 15 May 2015

ember.js - How to get routeparameter of subroute in Ember -



ember.js - How to get routeparameter of subroute in Ember -

i want list appointments of persons ember app. have route defined like:

this.resource('person', { path: "person/:personid/" }, function () { this.route('appointments', { path: "appointments/:date" }); });

now have 2 templates

person - template: show person's name @ top, {{outlet}}

appointments - template: has backward, date , forwards button navigate through dates , appointments listed

the controller of appointments handles navigation through dates

controller.transitiontoroute("person.appointments",mydatevar)

this rerenders buttons, because in same route. , don't that.

i tried different approaches when separate navigation appointment list, need deal date in 2 controllers, or routes, somehow.

the navigation needs know state of "subroute"-parameter of appointments-route. , think totally wrong.

i confused :-(

can help me out?

there 2 ways.

1. needs: http://emberjs.com/guides/controllers/dependencies-between-controllers/ 2. send: http://emberjs.com/api/classes/ember.route.html#method_send

you can set date on appointments controller , utilize needs in order share info person controller. doing can have alias appointment date on person controller.

app.personcontroller = em.objectcontroller.extend({ needs: 'appointments', date: ember.computed.alias('controllers.appointments.date') // whatever date property });

you can send action parent route informing date has changed.

app.personroute = em.route.extend({ actions: { datechanged: function(newdate){ this.controller.set('date', newdate); } } }); app.appointmentsroute = em.route.extend({ model: function(params){ this.send('datechanged', params.date); ... } });

ember.js routing

No comments:

Post a Comment