ユーザーが選択できるアイテムを含むグリッドと、グリッドのコンテンツをフィルター処理するために使用できる小さなテキスト フィールドを持つ、再利用可能なアイテム選択パネルを作成しようとしています。現在、(簡略化された) ビュー コードは次のようになり、動作します。
Ext.define('MyApp.view.items.ItemSelectorPanel', {
extend: 'Ext.panel.Panel',
require: 'MyApp.view.items.SimpleItemGrid',
alias: 'widget.ItemSelectorPanel',
layout: 'form',
config: {
itemStore: false
},
constructor: function(config) {
this.initConfig(config);
this.superclass.constructor.call(this, config);
this.add([
{
fieldLabel: 'Filter',
name: 'filter'
},
{
xtype: 'SimpleItemGrid',
collapsible: true,
store: this.getItemStore()
}
]);
return this;
}
});
ご覧のとおり、はプロパティをItemSelectorPanel
使用してconfig
、呼び出し元のサイトが使用するアイテム ストアを指定できるインターフェイスを公開します。
呼び出しサイト (この場合、パネルは TabPanel に追加されます):
var panelToAdd = {
xtype: 'panel',
title: 'New Selection',
closable: true,
padding: 10,
items: [{
title: 'Select node',
xtype: 'ItemSelectorPanel',
itemStore: itemStore
}]
};
今では、ExtJS 4 の宣言型スタイルと、それが MVC パターンに従うのにどのように役立つかが気に入っています。ビューで可能な限り最小限のコードを使用することをお勧めします。残念ながら、これは機能しません:
Ext.define('MyApp.view.items.ItemSelectorPanel', {
/* ... same as above ... */
constructor: function(config) {
this.initConfig(config);
this.superclass.constructor.call(this, config);
return this;
},
items: [
{
fieldLabel: 'Filter',
name: 'filter'
},
{
xtype: 'SimpleItemGrid',
collapsible: true,
store: this.getItemStore // <-- interesting part
}
]
});
config
親プロパティのプロパティを介してネストされた/サブコンポーネントの構成を宣言的に公開する方法はありますか?