Ember的currentPath和currentRouteName始终未定义

时间:2014-08-28 20:59:31

标签: javascript ember.js routes

MyEmberApp.ApplicationRoute = Ember.Route.extend({
  beforeModel: function() {
    console.log(this);
    console.log(this.controllerFor('application').get('currentPath')); // Undefined.
    console.log(this.controllerFor('application').currentPath); // Undefined.
    // console.log(this.controller.currentRouteName); // Undefined.
    // console.log(Mars.__container__.lookup("controller:application").get("currentRouteName")); // Undefined.
    // console.log(this.controllerFor("application").get("currentPath")); // Undefined.
    // console.log(this.controllerFor("application").get("currentRouteName")); // Undefined.

    this.transitionTo(THE ROUTE NAME I FIND...);
  }
});

我做错了什么?甚至官方文件都说我必须这样做http://emberjs.com/guides/understanding-ember/debugging/

2 个答案:

答案 0 :(得分:0)

文档未能指定您需要在ApplicationController上手动创建此属性。

MyEmberApp.ApplicationController = Ember.Controller.extend({
  currentPath: 'test12'
});

答案 1 :(得分:0)

在beforeModel挂钩上你还没有准备好控制器。尝试挂钩setupController。

setupController(controller, model) {
  this._super(controller, model);
  debugger;
},