骨干,从子视图访问父视图?

时间:2013-10-16 08:28:25

标签: backbone.js view backgrid

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

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

2 个答案:

答案 0 :(得分:29)

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

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

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

答案 1 :(得分:-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

  }
});
相关问题