Backbone.js:从子视图访问父视图?

k75qkfdt  于 2022-11-10  发布在  其他
关注(0)|答案(2)|浏览(174)

一般情况下,如何在Backbone中从子视图访问父视图?
具体来说,在Backgrid.js中,是否有一种方法可以从单元格访问父行?

fjnneemd

fjnneemd1#

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

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

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

eh57zj3b2#

// 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

  }
});

相关问题