Ember.js Ember App.Router.Router.currentState未定义

Ember.js Ember App.Router.Router.currentState未定义,ember.js,Ember.js,我想监控App.Router.Router.currentState以激活/停用导航链接。如下所述: 但是,属性currentState似乎不再存在于路由器中。 App.get'Router.Router.currentState'返回未定义 我想,它在最近的余烬版本中发生了变化。还有其他方法吗?对于我来说,当前版本有点复杂,但至少它可以工作: var router = App.__container__.lookup("router:main"); //lookup the router va

我想监控App.Router.Router.currentState以激活/停用导航链接。如下所述:

但是,属性currentState似乎不再存在于路由器中。 App.get'Router.Router.currentState'返回未定义


我想,它在最近的余烬版本中发生了变化。还有其他方法吗?

对于我来说,当前版本有点复杂,但至少它可以工作:

var router = App.__container__.lookup("router:main"); //lookup the router
var currentHandlerInfos = r.router.currentHandlerInfos; //there are multiple handlers active at one time
var activeHandler = currentHandlerInfos[currentHandlerInfos.length - 1]; // the last item in the array is the current handler with properties like name, context, handler (Ember.Route)
var activeRoute = activeHandler.handler; //your route object

这段代码的灵感来自阅读本文。我还没有在一个有很多路线的复杂应用程序中测试过它,但我很有信心,它会工作得很好。也许有人有一种更精干的方法来做到这一点:-

对于我来说,当前的版本有点复杂,但至少它可以工作:

var router = App.__container__.lookup("router:main"); //lookup the router
var currentHandlerInfos = r.router.currentHandlerInfos; //there are multiple handlers active at one time
var activeHandler = currentHandlerInfos[currentHandlerInfos.length - 1]; // the last item in the array is the current handler with properties like name, context, handler (Ember.Route)
var activeRoute = activeHandler.handler; //your route object

这段代码的灵感来自阅读本文。我还没有在一个有很多路线的复杂应用程序中测试过它,但我很有信心,它会工作得很好。也许有人有更精干的方法来做到这一点:-

好的。解决了这个问题。似乎currentPath是在applicationController实例中设置的。所以我这样做了:

App = Em.Application.create({

    currentPath: '',

    ApplicationController : Ember.Controller.extend({
        updateCurrentPath: function() {
            App.set('currentPath', this.get('currentPath'));
        }.observes('currentPath')
    }),

    ...

});

然后,我可以从代码中的任何位置绑定或观察App.currentPath,并对其更改做出反应。

确定。解决了这个问题。似乎currentPath是在applicationController实例中设置的。所以我这样做了:

App = Em.Application.create({

    currentPath: '',

    ApplicationController : Ember.Controller.extend({
        updateCurrentPath: function() {
            App.set('currentPath', this.get('currentPath'));
        }.observes('currentPath')
    }),

    ...

});

然后,我可以从代码中的任何位置绑定或观察App.currentPath,并对其更改作出反应。

我相信使用新的Ember版本实现这一点的教科书方法将是:

App.SomeController = Ember.Controller.extend({
    needs: 'application',
    someFunction: function(){
        var state = this.get('controllers.application.currentPath');
    }
})

我相信,使用新的Ember构建实现这一目标的教科书方法将是:

App.SomeController = Ember.Controller.extend({
    needs: 'application',
    someFunction: function(){
        var state = this.get('controllers.application.currentPath');
    }
})

这个例子来自我的组件。所有实体都有属性-容器

GetCurrentPath:-> app=@container.lookup'controller:application'
return app.get'currentPath'

从我的组件获取此示例。所有实体都有属性-容器

GetCurrentPath:-> app=@container.lookup'controller:application'
return app.get'currentPath'

是的,这就是我要做的。不幸的是,我无法绑定currentHandlerInfos来跟踪其内容。解决这个问题有点不同。然后更新你的问题plz,因为它不反映绑定的要求。是的。我举了一个我想要实现的例子。是的,这就是我想要做的。不幸的是,我无法绑定currentHandlerInfos来跟踪其内容。解决这个问题有点不同。然后更新你的问题plz,因为它不反映绑定的要求。是的。我举了一个我想要达到的目标的例子。这个技巧是