简体   繁体   English

在余烬中出现未捕获的错误

[英]Getting uncaught error in ember

When I'm doing the right click option for more than 5 (approx) times for certain task, it showing uncaught error as like below: 当我对某些任务执行右键单击选项超过5次(大约)时,它显示未捕获的错误,如下所示:

Uncaught TypeError: Cannot read property 'find' of undefined
    at Class.<anonymous> (core.js:21487)
    at fn (core.js:7779)
    at DeferredActionQueues.flush (core.js:7723)
    at Backburner.end (core.js:7738)
    at Backburner.run (core.js:7748)
    at executeTimers (core.js:7824)
    at core.js:7822

In that Place I'm having the below code: 在那个地方,我有以下代码:

Ember.run.later(view, function () {
    this.$().find('menu-item:eq(0)').focus();
}, 125);

Can anyone please suggest me why this error is coming and I need to avoid this error while right clicking the task for "n" number of time also. 任何人都可以建议我为什么会出现此错误,并且我还需要在右键单击任务“ n”次的同时避免此错误。 I'm new to the ember. 我是炭烬新手。 Your help will be appreciate. 您的帮助将不胜感激。 Thanks in advance. 提前致谢。

Thats a simple javascript issue. 多数民众赞成在一个简单的JavaScript问题。 In the second line this.$() returns undefined , and so it can't call .find on undefined. 在第二行中, this.$()返回undefined ,因此无法在undefined上调用.find

More interesting is why this.$() is undefined. 更有趣的是为什么 this.$()未定义。 Probably you have this code inside a component, and try to access the local jQuery instance . 可能您的代码在组件内部,然后尝试访问本地jQuery实例 However you call it inside an anonymous function(){} , which breaks your this -context (because it gets a new one). 但是你把它叫做一个匿名内部function(){}打破你的this -context(因为它获得一个新的)。

The best solution here is to use an arrow function: 最好的解决方案是使用箭头功能:

Ember.run.later(view, () => {
  this.$().find('menu-item:eq(0)').focus();
}, 125);

this prevents the outer this context, which is nice. 这样可以防止外部this上下文,这很好。 Another options is to save this: 另一种选择是保存此:

const self = this;
Ember.run.later(view, function () {
  self.$().find('menu-item:eq(0)').focus();
}, 125);

Or you can .bind(this) : 或者你可以.bind(this)

Ember.run.later(view, (function () {
  this.$().find('menu-item:eq(0)').focus();
}).bind(this), 125);

I can definitely recommend the first option, especially when using ember(-cli) which gives you transpilation anyway. 我绝对可以推荐第一种选择,尤其是在使用ember(-cli)时,无论如何它都能使您进行转译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 收到以下错误:compare.js:1 未捕获的错误:找不到模块“ember” - Getting this following error: compare.js:1 Uncaught Error: Cannot find module 'ember' 通过ember-cli创建应用程序获取“未捕获错误:断言失败:Ember视图需要1.7到2.1之间的jQuery” - Getting “Uncaught Error: Assertion Failed: Ember Views require jQuery between 1.7 and 2.1” with app created through ember-cli 灰烬JS:“未抓到的# <error> ”(来自{{#each}}声明 - Ember JS: “Uncaught #<error>” from {{#each}} statement Ember CLI - 未捕获错误:找不到模块余烬? - Ember CLI - Uncaught Error: Could not find module ember? 在Ember验收测试中出错 - Getting error in Ember Acceptance test 出现未捕获的错误:[$ injector:modulerr] - Getting Uncaught Error: [$injector:modulerr] 灰烬问题:未被捕获的错误:找不到模块把手 - Ember issue: Uncaught Error: Could not find module handlebars Ember Engine Uncaught错误:找不到模块ember-views / views / select - Ember Engine Uncaught Error: Could not find module ember-views/views/select Ember为什么在ember.js:3722上抛出“未捕获的错误:断言失败:在被破坏的对象上调用set”? - Why is Ember throwing “Uncaught Error: Assertion Failed: calling set on destroyed object” at ember.js:3722? Ember得到错误404(不正常),没有代码更改 - Ember getting error 404 (Not OK) with no code changes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM