如何在我的视图中绑定jquery事件 [英] How to bind jquery events in my view
本文介绍了如何在我的视图中绑定jquery事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用一些基于jquery的第三方库与ember。该库
绑定元素上的事件,如下所示:
I'd like to use some third party libraries that are based on jquery with ember. This library binds event on element like this :
$('#an-id')
.bind('anEvent', function (event, params) { ... })
我将事件enEvent捕获到我的Ember View中,并使用基于Ember的事件处理程序。如下:
How do I catch the event enEvent into my Ember View and use an Ember based event handler. Something like :
App.MyView = Em.View.create({
myEventHandler: function(event,params) { ....}
})
推荐答案
在视图上使用 didInsertElement
回调,当视图添加到DOM时,该回调将被调用。然后,您可以通过访问添加的元素$()
。
Use the didInsertElement
callback on a view, which gets invoked when the views has been added to the DOM. You can then access the added element via this.$()
.
App.MyView = Em.View.create({
didInsertElement: function() {
this.$().bind('anEvent', ...);
}
});
这篇关于如何在我的视图中绑定jquery事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文