简体   繁体   English

Ember如何在不指定hbs动作的情况下触发动作

[英]Ember How is action triggered without specifying action in the hbs

In my Ember app component my-component.hbs, I have 在我的Ember应用程序组件my-component.hbs中,

{{#my-grid gridInitialized="gridInstantiated" }}

Now in my-component.js, I have it defined as action below; 现在在my-component.js中,将其定义为以下操作;

actions: {
    gridInstantiated: function (myGrid) {       
    }
}

How/Why does the above syntax for action work ? 上述动作语法为何/为什么起作用? Specifically 特别

  1. "gridInstantiated" is not defined as normal property in my-component.js 在my-component.js中,“ gridInstantiated”未定义为常规属性
  2. In the hbs, it is defined without the "action" keyword 在hbs中,定义时不带“ action”关键字

Just wanted to know how it works given the above 2 points ? 只是想知道上述2点的工作原理?

*********EDITS************ *********编辑************

Just to add, I have the below code on my-grid component init call; 只需添加一下,我在my-grid组件的init调用中有以下代码;

this.sendAction('gridInitialized', Ember.$.proxy(this, function () {
    this.fetchData();
}));

In classic action, for triggering the action they will use this.sendAction("actionName") this will look for the actionName function in action hash call that function with corresponding context. 在经典动作中,为了触发动作,他们将使用this.sendAction("actionName")来在动作哈希调用中寻找具有相应上下文的actionName函数。

Its very well explained in https://embermap.com/notes/26-a-note-on-actions 它在https://embermap.com/notes/26-a-note-on-actions中得到了很好的解释

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM