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) { ... })
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) { ....}
})
The jQuery bind() event is used to attach one or more event handlers for selected elements from a set of elements. It specifies a function to run when the event occurs. It is generally used together with other events of jQuery. Syntax: $(selector).
jQuery bind() MethodUse the on() method instead. The bind() method attaches one or more event handlers for selected elements, and specifies a function to run when the event occurs.
jQuery's event system requires that a DOM element allow attaching data via a property on the element, so that events can be tracked and delivered. The object , embed , and applet elements cannot attach data, and therefore cannot have jQuery events bound to them.
bind() method is used for attaching an event handler directly to elements. Handlers are attached to the currently selected elements in the jQuery object, so those elements must exist at the point the call to . bind() occurs.
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', ...);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With