How to access dynamic segment in a controller in Ember.js?

前端 未结 4 1447
余生分开走
余生分开走 2021-02-14 01:07

I have an example route:

this.route(\'client\', {path: \':id\'});

I can access this in my route like this:

model: function(para         


        
4条回答
  •  花落未央
    2021-02-14 01:43

    There's a serialize function within the Route that you can take advantage of. Here's the API Documentation for it. However, in your context, you can just do this:

    App.IndexRoute = Em.Route.extend({
      model: function(params) {
        console.log(params.client_id);
      },
      serialize: function(model){
        return { client_id : model.id };
      }
    });
    

    Let me know if this works!

    I also noticed an error in your route definition. It should presumably be

    this.route('client', {path: '/:client_id'});
    

    or

    this.route('client', {path: '/client/:client_id'});
    

提交回复
热议问题