Ok. I have a simple question regarding how ember handles re-rendering of routes...
好。关于ember如何处理路由的重新呈现,我有一个简单的问题...
The Application
Stuff
-------------------------------
Ember : 1.8.1
Ember Data : 1.0.0-beta.12
Handlebars : 1.3.0
jQuery : 1.11.2
-------------------------------
Teh Codes
router.js
router.js
this.resource('categories', {path: '/categories'}, function(){
this.resource('category', {path:'/:cid'});
});
I have two very simple nested templates. One named categories
and one named category
. They work just as you would expect. However my ember app has no views defined in the application, just templates.
我有两个非常简单的嵌套模板。一个命名类别和一个命名类别。它们的工作方式与您期望的一样。但是我的ember应用程序没有在应用程序中定义的视图,只有模板。
The Question
How can I change a simple property of the parent route's controller, say foo: 0
from 0
to 1
when going from the parent to the child route via link-to
helpers only (i.e. not reloading the route via the address bar)?
如何更改父路由控制器的简单属性,例如foo:0从0到1时,从父路径到子路由仅通过链接到助手(即不通过地址栏重新加载路由)?
The solution needs to work when going from parent to child and vice versa, all from link-to
helpers, just to be clear. I have gotten this behavior to work when going from parent to child route, just not vice-versa.
解决方案需要在从父母到孩子的时候工作,反之亦然,所有这些都是从链接到帮助者,只是为了清楚。从父母到孩子的路线,我已经让这种行为发挥作用,反之亦然。
All I want to do is toggle this property of the parent route from 0
to 1
我想做的就是将父路由的这个属性从0切换到1
UPDATE
I want to basically toggle the foo
variable from 1
to 0
by navigating back and forth between the two routes. Imagine clicking on the link-to
between these two routes 10 times and just seeing the property of the parent route get updated each time to the new value. Why is this not a simple hook in the controller? What am i missing?
我想基本上通过在两条路线之间来回导航将foo变量从1切换到0。想象一下,点击这两条路线之间的链接10次,只看到父路线的属性每次更新到新值。为什么这不是控制器中的简单钩子?我错过了什么?
Vain Attempts Section
I have done a load of googling and tried lots of various hooks in the routes (beforeModel
,model
,setupController
) and controllers. I have had no success. Would welcome a dead-easy method for tackling this if there is one. My apologies if I am missing something here.
我已经完成了大量的谷歌搜索,并在路线(beforeModel,model,setupController)和控制器中尝试了很多各种钩子。我没有成功。如果有的话,欢迎一种解决这个问题的简单方法。如果我在这里遗漏了一些东西,我很抱歉。
1 个解决方案
#1
1
categories index route
类别索引路线
afterModel: function(model, transition){
if(Ember.isEqual(this.controllerFor('application').currentRouteName, "categories.index"))
{
this.controllerFor('categories.index').set('foo', 0);
}
}
category route
类别路线
afterModel: function(model, transition){
if(Ember.isEqual(this.controllerFor('application').currentRouteName, "category"))
{
this.controllerFor('categories.index').set('foo', 1);
}
}
stick a debug on this.controllerFor('application').currentRouteName
when on each of these pages to make sure I have the names of the routes right but that should do the trick
在this.controllerFor('application')上粘贴调试。当每个页面上的currentRouteName确保我有正确的路由名称,但这应该做的伎俩
#1
1
categories index route
类别索引路线
afterModel: function(model, transition){
if(Ember.isEqual(this.controllerFor('application').currentRouteName, "categories.index"))
{
this.controllerFor('categories.index').set('foo', 0);
}
}
category route
类别路线
afterModel: function(model, transition){
if(Ember.isEqual(this.controllerFor('application').currentRouteName, "category"))
{
this.controllerFor('categories.index').set('foo', 1);
}
}
stick a debug on this.controllerFor('application').currentRouteName
when on each of these pages to make sure I have the names of the routes right but that should do the trick
在this.controllerFor('application')上粘贴调试。当每个页面上的currentRouteName确保我有正确的路由名称,但这应该做的伎俩