17

一般来说,如何从 Backbone 中的子视图访问父视图?

具体来说,在 Backgrid.js 中,有没有办法从单元格访问父行?

4

2 回答 2

30

this在初始化步骤中作为选项传递给子视图:

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

// somewhere in the parent view ...
new ChildView({parent:this});
于 2013-10-16T09:25:10.510 回答
-2
// You can use this code instead

var ChildView = Backbone.View.extend({
  initialize : function (options) {
    this._configure(options); // Set all the options as local variables
    // This is used in the Backbone.View code on the latest version

  }
});
于 2014-02-25T16:42:33.213 回答