Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.JS Custom Event from Child View

I have two views, for simplicity sake a parent/child. The child is using trigger to throw an event. I am not seeing it in the handler of the parent. Is the below valid?

var parent = Backbone.View.extend({
    events: { "childevent": "run" },
    run: function(e) {
       console.log(e);
    }, 
    render: function() { /* render the child here */ }
});

var child = Backbone.View.extend({
    someAction: function() { this.trigger('childevent'); }
});
like image 535
Justin Thomas Avatar asked Jul 20 '11 02:07

Justin Thomas


1 Answers

Figured it out! $(this.el).trigger('childevent'); works.

like image 152
Justin Thomas Avatar answered Sep 29 '22 13:09

Justin Thomas