[英]Uncaught TypeError: Cannot read property 'enter' of undefined , while using transitionToRoute
I am getting an "Uncaught TypeError: Cannot read property 'enter' of undefined". 我收到“未捕获的TypeError:无法读取未定义的属性'enter'”。 This is when i am using transitionToRoute in a controller.
这是当我在控制器中使用transitionToRoute时。 The transitionToRoute function in controller,
控制器中的transitionToRoute函数,
transitionToRoute: function() {
// target may be either another controller or a router
var target = get(this, 'target');
var method = target.transitionToRoute || target.transitionTo;
return method.apply(target, arguments);
},
here the target variable is being assigned a view instead of controller or router. 在这里,为目标变量分配了一个视图,而不是控制器或路由器。 I don't know if this is a issue or am i using transitionToRoute in a wrong way.
我不知道这是一个问题还是我以错误的方式使用transitionToRoute。 Need help here.
在这里需要帮助。
EDIT: The above function can be found here, https://github.com/emberjs/ember.js/tree/v2.0.1/packages/ember-routing/lib/ext/controller.js#L41 编辑:上面的功能可以在这里找到, https://github.com/emberjs/ember.js/tree/v2.0.1/packages/ember-routing/lib/ext/controller.js#L41
EDIT: In the above function, it calls get function with a controller object as "this", looking for "target" key in it. 编辑:在上面的函数中,它将调用控制器对象为“ this”的get函数,在其中查找“目标”键。 When i log "this.target" in transitionToRoute it prints a route class, but if i log the same variable in get function i get a view class.
当我在transitionToRoute中记录“ this.target”时,它会打印一个路由类,但是如果我在get函数中记录了相同的变量,则会得到一个视图类。
I have no clue how this is happening. 我不知道这是怎么回事。
Try 尝试
transitionToRoute: function() {
// target may be either another controller or a router
var target = get(this, 'target');
var method = target.transitionToRoute || **this.target.transitionTo;**
return method.apply(target, arguments);
},
Here, the controller's transitionToRoute function is getting its route and calling route's transitionTo function. 在这里,控制器的transitionToRoute函数获取其路由并调用路由的transitionTo函数。 So, as a workaround we can directly get route in controller and call transitionTo()
因此,作为一种解决方法,我们可以直接在控制器中获取路由并调用transitionTo()
//inside controller
this.get('target').transitionTo(arguments);
But still would love to know why this is happening. 但是仍然很想知道为什么会这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.