一般来说,如何从 Backbone 中的子视图访问父视图?
具体来说,在 Backgrid.js 中,有没有办法从单元格访问父行?
在初始化步骤中将this
作为选项传递给子视图:
var ChildView = Backbone.View.extend({
initialize : function (options) {
this.parent = options.parent;
}
});
// somewhere in the parent view ...
new ChildView({parent:this});
// 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
}
});