[英]Basic use of `this` in Ember.js
我相當精通Java語言,但是很難理解Ember在某些情況下如何處理this
上下文。
我有一個組件控制器:
import Component from '@ember/component';
export default Component.extend({
keyPress(e) {
// here I want to call a method in the `actions` hash
this.get('onAccept')
},
actions: {
onAccept() {
console.log('action accepted!')
}
}
}
但是,每次運行此命令時,都會出現以下錯誤:
Uncaught TypeError: this.get(...) is not a function
這似乎當我有以外的方法經常發生actions
哈希需要訪問內部的功能actions
的散列, 或者反過來。
而且這種行為似乎是必需的,因為組件事件屬於actions hash之外 。
那么,我應該如何在actions
哈希之外具有事件方法,但仍然能夠調用在actions
哈希內部屬於的方法呢?
在Ember中,這似乎是控制器中記錄很少的一部分。 也許我只是在這里想念東西。 任何幫助是極大的贊賞。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.