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

前端 未结 4 1450
余生分开走
余生分开走 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:45

    I just came across this question since I too was wondering what was the best way to do this. I chose to go via the route of returning a hash from the model rather than setting parameters in the route.

    So in your case I would do the following:

    model() {
      Ember.RSVP.hash({client: , id: id});
    }
    

    And then in the controller or template I can access the client by calling

    model.client
    

    and get the id by calling

    model.id
    

    I personally feel this is a cleaner way of accessing the id as compared to setting a param on the route. Of course I am assuming that the id is not already set on the model. Otherwise this entire exercise is pointless.

提交回复
热议问题