lundi 20 mars 2017

Ember optional query params

I need to use optional query parameters and despite following previous posts I'm struggling to get it working.

My app is for posting teaching sessions. The setup is:

  • A user can post a teaching session. They can also request a teaching session.
  • If they post a session I use the sessions.new route. In this route the model object returns a new session object with default settings.
  • If they respond to a teaching request I want to pass the teaching request ID to the sessions.new route so that I can pre-populate the model with information from the request, and link the session to the request
  • This is complicated by the fact that I use a multiple page 'wizard' for session creation, so the sessions.new route actually has multiple sub-routes (sessions.new.wizard1, sessions.new.wizard2 etc.)

My current setup looks like this:

Router:

this.route('sessions', function(){
    this.route('new', function(){
        this.route('wizard1');
        this.route('wizard1');
        this.route('wizard3');
        this.route('from-request', {path: 'from-request/:request_id'});
    })
})

The model is defined on the sessions.new route and is shared between sub-routes.

I want to do something like this in the from-request sub-route:

afterModel: function(model, transition){
    this.store.findRecord('request', transition.queryParams.request_id).then(function(request){
        model.set('info', request.get('info'));
    });
    this.transitionTo('sessions.new.wizard1');
} 

This doesn't seem to work at all. I can't access the queryParams on the transition object as I would expect to. Furthermore anything I set on the model does not seem to persist after the transition.

Is there a better way to do this? Am I missing something?

Many thanks




Aucun commentaire:

Enregistrer un commentaire