如何处理ember.js组件中的自定义事件? [英] how to deal with custom events in ember.js component?
问题描述
didInsertElement
方法中)。这个图书馆有自己的事件。他们可以在简单的JS中看起来像这样: $('fotorama')。on('fotorama:ready' (e,fotorama){});
或:
('fotorama:show',function(){}); code> $
但我觉得在Ember中,应该以某种方式映射到组件中的操作。
我的问题是:怎么样?我需要在这些动作中触发一些动作(被其他组件或路由器所捕获)。所以我认为应该是这样的: this.sendAction('actionName',actionParams);
您可以保留组件引用来调用sendAction方法。
didInsertElement(){
this._super(...参数);
var _this = this;
this。$('。fotorama')。on('fotorama:show',function(){
_this.sendAction('actionName',actionParams);
});
}
willDestroyElement(){
this._super(... arguments);
这个$('。fotorama')。off('fotorama:show')
}
如果我们找到一个更好的答案这个问题。我会高兴地删除我的答案。
I'm new to Ember.js and I've got some problems to understand its philosophy. I know actions up, data down but in real life, lets say I have Fotorama initialized in my-gallery component (I don't know if that is ok, but I did it in didInsertElement
method). This library has its own events. They could look like this in plain JS:
$('.fotorama').on('fotorama:ready', function (e, fotorama) {});
or:
$('.fotorama').on('fotorama:show', function () {});
but I feel in Ember, those should be somehow mapped into actions in component.
My question is: how? I need to fire some actions (to be catched by another components or maybe a router) inside those actions. So I think it should be like this: this.sendAction('actionName', actionParams);
You can keep component reference to call sendAction method.
didInsertElement(){
this._super(...arguments);
var _this=this;
this.$('.fotorama').on('fotorama:show', function () {
_this.sendAction('actionName', actionParams);
});
}
willDestroyElement(){
this._super(...arguments);
this.$('.fotorama').off('fotorama:show')
}
If we find an better answer to this question. I will happily remove my answer.
这篇关于如何处理ember.js组件中的自定义事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!