Vijay Singh
Vijay Singh

Reputation: 277

Marionette ItemView events - bind multiple functions to single event

Is it possible to bind multiple functions to single event in a Marionette ItemView
eg.

events: { 
"click #div1": "func1 func2" 
}

This doesn't work at all in ItemView. However, its supposed to work fine in CollectionView: https://github.com/marionettejs/backbone.marionette/issues/355.

I also tried

events: { 
"click #div1": "func1",
"click #div1": "func2" 
}

But this results in a call only to func2!

Upvotes: 2

Views: 460

Answers (1)

ivarni
ivarni

Reputation: 17878

Your events is an object, and Backbone iterates over its keys and since you can't have duplicate keys you can't declare two handlers on the same event.

You can instead use a single event-handler that again calls the functions you want to invoke.

events: {
    'click #div1': 'onDiv1Click'
},

onDiv1Click: function() {
    this.func1();
    this.func2();
}

Upvotes: 4

Related Questions