![](/img/trans.png)
[英]Getting this following error: compare.js:1 Uncaught Error: Cannot find module 'ember'
[英]Getting uncaught error in ember
當我對某些任務執行右鍵單擊選項超過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
在那個地方,我有以下代碼:
Ember.run.later(view, function () {
this.$().find('menu-item:eq(0)').focus();
}, 125);
任何人都可以建議我為什么會出現此錯誤,並且我還需要在右鍵單擊任務“ n”次的同時避免此錯誤。 我是炭燼新手。 您的幫助將不勝感激。 提前致謝。
多數民眾贊成在一個簡單的JavaScript問題。 在第二行中, this.$()
返回undefined
,因此無法在undefined上調用.find
。
更有趣的是為什么 this.$()
未定義。 可能您的代碼在組件內部,然后嘗試訪問本地jQuery
實例 。 但是你把它叫做一個匿名內部function(){}
打破你的this
-context(因為它獲得一個新的)。
最好的解決方案是使用箭頭功能:
Ember.run.later(view, () => {
this.$().find('menu-item:eq(0)').focus();
}, 125);
這樣可以防止外部this
上下文,這很好。 另一種選擇是保存此:
const self = this;
Ember.run.later(view, function () {
self.$().find('menu-item:eq(0)').focus();
}, 125);
或者你可以.bind(this)
:
Ember.run.later(view, (function () {
this.$().find('menu-item:eq(0)').focus();
}).bind(this), 125);
我絕對可以推薦第一種選擇,尤其是在使用ember(-cli)時,無論如何它都能使您進行轉譯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.