I have a main view and inside that main view I have another view that gets created when I click a button. Is there a way to listen for a custom event on the parent view for an event that is fired from the child view. I tried to do it through the el property using jQuery trigger but that didn't quite work.
Ya, no problem... you'll want to use the "Event Aggregator" pattern. It's 1 line of code in Backbone:
var eventAgg = _.extend({}, Backbone.Events);
Now can you trigger / bind to events from this object, everywhere in your app, and have the different parts of your app communicate with each other in a decoupled manner.
I use this a LOT!
I also blogged more about it here: http://lostechies.com/derickbailey/2011/07/19/references-routing-and-the-event-aggregator-coordinating-views-in-backbone-js/
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