Reputation: 41
Like in the events hash in a backbone view we specify events with a selector, Example:-
events: {
"click .icon": "open",
"click .button.edit": "openEditDialog",
"click .button.delete": "destroy"
}
How do you implement this with listenTo
this.listenTo('Events','mouseenter .icon',callback)
PS: I have multiple components( like buttons,checkboxes) and I have a UI which allows to bind listeners to those components in the DOM(allows component interaction). They have click,mouseenter etc default javascript events handled and triggered like for click and double-click something like this:-
Events.trigger('click',data);
or
Events.trigger('dblClick',data);
But I want to bind the listeners to specific components only, prohibiting the recipient from listening to mouseenter of all the existing dom components as mouseenter of any component will lead to Events.trigger('mouseenter',data).
Upvotes: 0
Views: 1036
Reputation: 316
I think you're confusing between DOM events from Backbone.Events -- they are not the same.
The events hash apply only to Backbone.View, and refers to DOM events that can be tied to event handler methods in your View.
listenTo()
is a method in Backbone.Events that can apply to any object that mixes in Backbone.Events. The first parameter in your listenTo()
method should be an object that has mixed in Backbone.Events.
Upvotes: 1