我想每次按下esc_key时在对象控制器中调用我的动作。 .observes()

时间:2023-01-29 21:12:44

I'm reading the Ember docs on the .observes() method but I'm still confused as to how to use observes() to detect something like a keyDown.

我正在阅读.observes()方法中的Ember文档,但我仍然对如何使用observes()来检测像keyDown这样的东西感到困惑。

So we're in an Object Controller for this example.

所以我们在这个例子的对象控制器中。

someAction: function() {
  console.log('This will be written in the console every time the esc_key has been pressed on this page. 
}.observes(the esc_key being pressed),

1 个解决方案

#1


1  

observes watches properties in the model, not actions the user takes. Events, like keyDown, get tracked and handled by the view layer (which by convention has the same name as the template)

观察模型中的监视属性,而不是用户采取的操作。事件,如keyDown,由视图层跟踪和处理(按照惯例,它与模板具有相同的名称)

See the following link for more info:

有关详细信息,请参阅以下链接:

http://emberjs.com/guides/understanding-ember/the-view-layer/

http://emberjs.com/guides/understanding-ember/the-view-layer/

#1


1  

observes watches properties in the model, not actions the user takes. Events, like keyDown, get tracked and handled by the view layer (which by convention has the same name as the template)

观察模型中的监视属性,而不是用户采取的操作。事件,如keyDown,由视图层跟踪和处理(按照惯例,它与模板具有相同的名称)

See the following link for more info:

有关详细信息,请参阅以下链接:

http://emberjs.com/guides/understanding-ember/the-view-layer/

http://emberjs.com/guides/understanding-ember/the-view-layer/