一般来说,如何从Backbone中的子视图访问父视图?
具体来说,在Backgrid.js中,有没有办法从单元格访问父行?
答案 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
}
});