Ember深层嵌套的路由不保留父动态参数 [英] Ember deeply nested routes do not keep parent dynamic parameter

查看:145
本文介绍了Ember深层嵌套的路由不保留父动态参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个ember应用程序:

I've got this ember application:

Ember       : 1.3.2
Ember Model : 0.0.11
Handlebars  : 1.3.0
jQuery      : 1.9.1 

使用此资源地图:

App.Router.map(function () {
  this.resource('dimensions', function() {
    this.resource('dimension', { path: ':dimension_id'}, function () {
      this.resource('value', { path: 'values/:value_id' });
    });
  });
});

这样我就可以在{维度}模板中嵌入{ 模板,并将{{outlet}}嵌入dimension模板中,并填充value模板。

And this allows me to embed {{outlet}} in "dimensions" template that fills with "dimension" template, and embed {{outlet}} in "dimension" template that fills with "value" template as well.

除了链接到帮助者在值模板中,不接受更多的参数,也不接受其他模型,如ember API文档中所述。

All works very well except for the link-to helper in the "value" template, that does not accept more params nor accepts other models as described in ember API documentation.

哪些是处理link-到深深嵌套的路线?

Which is the best way of dealing with link-to in deeply nested routes?

我有这个小提琴显示我的问题:
http://jsfiddle.net/vsiguero/pQpE3/5/

I've got this fiddle to show my problem: http://jsfiddle.net/vsiguero/pQpE3/5/

感谢您的帮助!

推荐答案

编辑:我写了这个答案后,添加了一些时间的 paramsFor 这可能。请参阅@nickiaconis的答案了解更多详情。

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

如果我正确理解你,我认为你正在预期行为。路由的参数对于该路由是唯一的。我不是100%确定为什么,但动态段值不会传递到子路由。您应该做的是直接访问模型。在路由中,您可以使用 this.modelFor('dimension')获取解析的模型维度路线。

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.

这篇关于Ember深层嵌套的路由不保留父动态参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆