简体   繁体   English

Uncaught TypeError:使用transitionToRoute时,无法读取undefined的属性“ enter”

[英]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.

相关问题 未捕获的TypeError:无法读取未定义的属性“未定义” - Uncaught TypeError: Cannot read property 'undefined' of undefined Angular Carousels:未捕获TypeError:在Angular JS中使用Carousels时,无法读取未定义的属性'offsetWidth' - Angular Carousels: Uncaught TypeError: Cannot read property 'offsetWidth' of undefined while using carousels with Angular JS `Uncaught TypeError:使用EasyXDM发送跨域消息时无法读取未定义`错误的属性'postMessage' - `Uncaught TypeError: Cannot read property 'postMessage' of undefined ` error while sending cross domain messages using EasyXDM Uncaught TypeError:无法读取未定义的属性“ chooseEntry”(在使用fileSystem API开发chrome扩展时) - Uncaught TypeError: Cannot read property 'chooseEntry' of undefined (while developing a chrome extension using fileSystem API) 使用jquery获取导入Gmail联系人时(“未捕获的TypeError:无法读取未定义的属性'0') - While importing gmail contact by using jquery getting ("Uncaught TypeError: Cannot read property '0' of undefined) 未捕获的类型错误:使用 Rcipe API 时无法读取未定义的属性“映射” - Uncaught TypeError: Cannot read property 'map' of undefined while using Rcipe API vendor.js:未捕获的TypeError:使用Webpack时无法读取未定义的属性“ apply” - vendors.js: Uncaught TypeError: Cannot read property 'apply' of undefined while using webpack 未捕获的类型错误:无法读取未定义的属性“createDocumentFragment”(使用所见即所得) - Uncaught TypeError: Cannot read property 'createDocumentFragment' of undefined (using wysiwyg) 未捕获的TypeError:使用for循环时无法读取未定义的属性'style' - Uncaught TypeError: Cannot read property 'style' of undefined when using for loop React - 未捕获的类型错误:无法使用 Airtable 读取未定义的属性“名称” - React - Uncaught TypeError: Cannot read property "name' of undefined using Airtable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM