Ember App.Router.router.currentState未定义 [英] Ember App.Router.router.currentState undefined
问题描述
我想监视App.Router.router.currentState,以激活/停用导航链接。沿着这里所解释的一些内容: https://stackoverflow.com/a/13312466/674525
I want to monitor App.Router.router.currentState for the purpose of activating/deactivating the navigation links. Something along the lines as explained here: https://stackoverflow.com/a/13312466/674525
但是,currentState的属性似乎不再存在于路由器中。
App.get('Router.router.currentState')返回未定义。
However, the property currentState does not seem to exist in the router any more. App.get('Router.router.currentState') returns undefined.
我想,它在最近的Ember版本中更改。有另外一种方式吗?
I suppose, it changed in the recent Ember versions. Is there another way of doing this?
推荐答案
好的。得到这个解决了看来,currentPath是在applicationController实例中设置的。所以我这样做:
Ok. Got this solved. It seems that the currentPath is set in the applicationController instance. So I did this:
App = Em.Application.create({
currentPath: '',
ApplicationController : Ember.Controller.extend({
updateCurrentPath: function() {
App.set('currentPath', this.get('currentPath'));
}.observes('currentPath')
}),
...
});
然后,我可以从代码中的任何地方绑定或观察App.currentPath,并对其更改做出反应。
Then, I can bind or observe the App.currentPath from anywhere in the code and react on its changes.
这篇关于Ember App.Router.router.currentState未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!