我有使用Backbone和RequireJS的问题。骨干+ RequireJS对象继承
BaseListView.js
define(['backgrid',
'backbone',
'underscore', etc.], function (
Backgrid,
Backbone,
_) {
return Backbone.View.extend({
initialize: function() {
if(needDeleteCell) {
this.addDeleteCell();
}
this.render();
},
addDeleteCell: function() {
var ListViewDeleteCell = DeleteCell.extend({
defaults: {
successMsg: this.attributes.deleteSuccessMsg,
failureMsg: this.attributes.deleteFailureMsg
}
});
this.columns.push({
name: "delete",
label: "",
editable: false,
cell: ListViewDeleteCell
});
}
});
});
ChildView.js
define(['i18next', './common/BaseListView'], function (i18n, BaseListView) {
'use strict';
return BaseListView.extend({
columns: [{
name: "_id",
label: i18n.t('app.operationForm.id'),
editable: false,
cell: "string",
renderable: false
}, {
name: "name",
label: i18n.t('app.operationForm.nameLabel'),
editable: false,
cell: "string"
}]
});
});
现在,如果我想要使用子视图的多个实例,我有多个“删除”列(由于BaseListView中的columns.push()),就像父级的columns
属性是单例实例一样。
在这种情况下,ChildView不延长BaseListView
什么是Bacbkone + RequireJS这样做的正确方法是唯一的类?
谢谢。
编辑:这是相同的问题:Switching between singleton and prototype scope using RequireJS但我想避免工厂解决方案。
感谢您的解决方案,它的工作原理以及@托马斯-的Jakub-RUP一个,我只是接受了他的解决方案,因为它需要较少的变化。 – plrenaudin