ExtJs Grid パネルを拡張する次の 2 つのクラスがあります。
- ReadonlyDataGrid - 名前が示すように、基本的な編集不可能な ExtJs グリッド
- EditableDataGrid - セルと行の編集プラグインを備えた ExtJs グリッド
ここで、開発者がグリッド JSON 構成で設定したプロパティに基づいて、上記の 2 つのクラスのいずれかを拡張する新しいクラスを提供したいと考えています。
例:
ジャワ:
parentObj.put("gridType", "readonly");
JS:
Ext.define('Grid.view.GridFactory', {
extend: 'Grid.view.AbstractGridFactory',
alias: 'widget.gridfactory',
singleton: true,
create : function(model){
var grid;
switch(model.input.gridType)
{
case 'readonly':
grid = new Grid class extending the ReadonlyDataGrid class;
break;
case 'editable':
grid = new Grid class extending the EditableDataGrid class;
break;
}
return grid;
}
});
現在、これを処理するには、2 つの別個のクラス ファイルを作成する必要があります。
クラス 1:
Ext.define('Grid.view.EditableGrid',{
extend : 'Grid.view.EditableDataGrid',
.... //additional features
});
クラス 2:
Ext.define('Grid.view.ReadonlyGrid',{
extend : 'Grid.view.ReadOnlyDataGrid',
.... //additional features
});
- これらの 2 つのクラスを 1 つにマージするにはどうすればよいですか?
- 上記のように、ユーザー構成に基づいて拡張プロパティを変更したり、正しいクラスを拡張したりするにはどうすればよいですか?
- デザイン的にはどちらが良いですか?クラスが 1 つあり、実行時にスーパークラスを変更するか、2 つのクラスを維持しますが、冗長/同じコードを使用しますか?