例如。resource1>resource1.resource2
Emberjs似乎都是为了减少代码量。对于我看不到的资源,是否有一些用例可以解释为什么应该以这种方式定义资源。
我无法让我的示例在jsfiddle或jsbin中工作,所以我在这里托管了它:http://emberjs.mattmazzola.net/
我的解决方案基于类似StackOverflow中描述的技术。问题如下:Ember.js pre4多嵌套路由
基本上,你注意到我有一个资源"动物",子资源"猫"one_answers"狗"。然而如果我把它们分别命名为"猫"one_answers"狗",路由器会说"找不到路由animals.cats。然后,如果我添加"animals."前缀使嵌套路由为"animals.casts",则url将变为索引#/amers/animals.cats,这没有意义。当然,我们通过覆盖路径属性来解决此问题,但我不明白为什么Emberjs默认情况下不这样做。我是否错误地定义了资源/路由,这是一个副作用?
换句话说,我目前正在执行以下操作:
App.Router.map(function() {
this.resource('products', function() {
this.route('desktops');
this.route('laptops');
});
this.resource('animals', function() {
// the url for this route is bad, but default behavior?
this.resource('animals.cats', function() {
this.route('cat', {path: ':cat_id'});
});
// Why does this require stating the parent route 'animals' again?
this.resource('animals.dogs', {path: 'dogs/'}, function() {
this.route('dog', {path: ':dog_id'});
});
});
});
如何编写这样的路由:
App.Router.map(function() {
this.resource('products', function() {
this.route('desktops');
this.route('laptops');
});
this.resource('animals', function() {
this.resource('cats', function() {
this.route('cat', {path: ':cat_id'});
});
this.resource('dogs', function() {
this.route('dog', {path: ':dog_id'});
});
});
});
hmm,我认为如果正确定义了App.AnimalsIndexRoute
、App.CatsIndexRoute
和App.DogsIndexRoute
(可能还有其他一些Ember.Routes(,第二个版本应该可以工作。如果你仍然有这个问题,你可以在这里或jsfiddle中发布其余的代码吗?