Ember deeply nested routes do not keep parent dynamic parameter

泄露秘密 提交于 2019-12-05 01:32:34
GJK

EDIT: The paramsFor method was added some time after I wrote this answer, which makes this possible. Refer to @nickiaconis' answer for more details.


If I understand you correctly, I think you're running into expected behavior. The parameters for a route are unique to that route. I'm not 100% sure why that is, but dynamic segment values don't get passed to child routes. What you should do instead is access the model directly. In your value route, you can use this.modelFor('dimension') to get the model that was resolved for the dimension route.

You can access parent routes' parameters from a child route like so:

this.paramsFor(parent_route_name).param_name

So you'd do something like this in your /app/routes/dimensions/dimension/value.js file:

export default Ember.Route.extend({
  model: function(params, transition) {
    var dimension_id = this.paramsFor('dimension').dimension_id;
    // do whatever you need with dimension_id and params.value_id
  }
});

Here's a fork of your jsFiddle, modified and working: http://jsfiddle.net/niaconis/kxejh9yr/
Note that I updated Ember.

Here is the documentation for Route#paramsFor: http://emberjs.com/api/classes/Ember.Route.html#method_paramsFor

I believe the latest ember 1.5+ applies any models or literal values given to the link-to helper from child to parent so you don't have to provide models for the full model path as they will default to the current route path.

Also you have access to parent models via the transition argument passed into model() using transition.resolvedModels from memory. Each dynamic route segment in the route path will be an an attribute on that object so make sure your router DSL specifies distinct names for each segment parameter name (as you currently do). So in your ValueRoute you can do something like:

model: function(params,transition) {
    return transition.resolvedModels.dimension;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!