Backbone.js: access parent view from child view?

eugene picture eugene · Oct 16, 2013 · Viewed 13.9k times · Source

In general, how to access parent view from a child view in Backbone?

Specifically, in Backgrid.js, is there a way to access parent row from a cell?

Answer

Vitalii Petrychuk picture Vitalii Petrychuk · Oct 16, 2013

Pass this as an option to the child view on initialization step:

var ChildView = Backbone.View.extend({
  initialize : function (options) {
    this.parent = options.parent;
  }
});

// somewhere in the parent view ...
new ChildView({parent:this});