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屋!