我有使用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