问题: 如何以正确的方式扩展BaseView
和Marionette.LayoutView
?
我有:类似的观点:
var MyView = BaseView.extend({
initialize: function(options) {
this._super(options); // backbone-super.js
...
}
});
我希望:将MyView
移至Marionette
视图。有两种方法:
1)问题是this._super
停止工作。我想Backbone
试图在initialize
Marionette.LayoutView
方法
var MyView = BaseView.extend(Marionette.LayoutView.prototype).extend({
initialize: function(options) {
this._super(options); // NOT WORK
this.regionManager.addRegions(options.regions); // WORK
...
}
})
2)这种方法的问题是MyView.regionManager
是undefined
。我认为原型指向BaseView
var MyView = Marionette.LayoutView.extend(BaseView.prototype).extend({
initialize: function(options) {
this._super(options); // WORK
this.regionManager.addRegions(options.regions); // NOT WORK
...
}
})
答案 0 :(得分:0)
试试这样:
var View = BaseView.extend({
constructor: function () {
BaseView.prototype.constructor.apply(this, arguments);
Backbone.LayoutView.prototype.constructor.apply(this, arguments);
}
});
_.extend(View.prototype, Backbone.LayoutView.prototype);