I am using backbone js. suppose i have a child view called 'childView' and a parent view called 'parentView'.
parentView = Backbone.View.extend({
render: function () {
new childView().render();
}
})
childView = Backbone.View.extend({
render: function () {
},
events: {
'click .abc' : 'fireEvent'
}
})
I need to call click event written in childView in a parentView.
The simplest way is to use
Backbone.View
's instance.Backbone.View
is mixed withBackbone.Events
which give you possibility to use it as event aggregator.Example for your case:
And in parent view:
This way you can subscribe to childView events, but you need to manually manage unbinding from all subscriptions.
Another solution for the same issue can be found by declaring global event aggregator for both views.
And in your views just trigger needed events with
vent.trigger
and subscribe/unsubscribe withvent.(on/off)
methods.