0

ここで述べたのとほぼ同じ質問があります: Set listener for store events in a controllerですが、さまざまなソリューションをすべて試しましたが、どれも機能しません。私のお気に入りの解決策は次のとおりです。

Ext.define('Photoalbum.view.Table', {
extend : 'Ext.dataview.DataView',
xtype  : 'photoalbum-table',

config : {
    width: 3000, 
    height: 3000,
    itemTpl: new Ext.XTemplate(
        '<tpl for=".">',
        '<div class="x-panel x-floating" style="width: {width+12}px !important; height: {height+12}px !important; top: {top}px !important; left: {left}px !important;">',
        '   <img src="{url}">',
        '</div></tpl>'
    )
},

constructor : function(config) {
    Ext.apply(config, {
        store : Ext.create('Photoalbum.store.Images')   //I don't like using storeId (or any other id) so I create the store class
    });

    this.callParent([config]);
    this.getStore().on('load', Photoalbum.getController('App').handleImagesLoad, this);
    this.getStore().load();
}
});

そこで、次の例外が発生します。

Uncaught TypeError: Object #<Object> has no method 'getController'
Ext.define.constructorTable.js:23
Ext.apply.create.fsencha-touch-all.js:15
(anonymous function)
Ext.ClassManager.instantiatesencha-touch-all.js:15
Ext.ClassManager.instantiateByAliassencha-touch-all.js:15
Ext.apply.factorysencha-touch-all.js:15
Ext.define.factoryItemsencha-touch-all.js:15
Ext.define.addsencha-touch-all.js:15
b.implement.callParentsencha-touch-all.js:15
override.addsencha-touch-all.js:15
Ext.define.applyItemssencha-touch-all.js:15
b.registerPreprocessor.Ext.Object.each.i.(anonymous function)sencha-touch-all.js:15
b.registerPreprocessor.Ext.Object.each.i.(anonymous function).g.(anonymous     function)sencha-touch-all.js:15
Ext.define.applyActiveItemsencha-touch-all.js:15
(anonymous function)sencha-touch-all.js:15
b.implement.initConfigsencha-touch-all.js:15
Ext.define.initializesencha-touch-all.js:15
Ext.define.constructorsencha-touch-all.js:15
b.implement.callParentsencha-touch-all.js:15
Ext.define.constructorsencha-touch-all.js:15
b.implement.callParentsencha-touch-all.js:15
Ext.define.override.constructorsencha-touch-all.js:15
b.implement.callParentsencha-touch-all.js:15
Ext.define.constructorsencha-touch-all.js:15
b.implement.callParentsencha-touch-all.js:15
override.constructorsencha-touch-all.js:15
Ext.apply.create.fsencha-touch-all.js:15
(anonymous function)
Ext.ClassManager.instantiatesencha-touch-all.js:15
(anonymous function)sencha-touch-all.js:15
Ext.apply.createsencha-touch-all.js:15
Ext.define.onBeforeLaunchApplication.js:30
Ext.apply.onDocumentReadysencha-touch-all.js:15
Ext.apply.onReady.nsencha-touch-all.js:15
Ext.apply.triggerReadysencha-touch-all.js:15
Ext.apply.refreshQueuesencha-touch-all.js:15
Ext.apply.refreshQueuesencha-touch-all.js:15
Ext.apply.refreshQueuesencha-touch-all.js:15
Ext.apply.onFileLoadedsencha-touch-all.js:15
(anonymous function)sencha-touch-all.js:15
Ext.apply.injectScriptElement.ksencha-touch-all.js:15

コントローラー定義関数を呼び出そうとする代わりに、自己定義関数を呼び出すと、機能します。上記の他の方法では、関数が呼び出されないか、画像がビューに表示されません。ほとんどの場合、コンソール出力はありません。

それを実装した良い例はありますか?これまでのところ、コンポーネント イベントしか見つかりません。

よろしくお願いします、ダニエル

4

1 に答える 1

0

Sencha MVC アーキテクチャを使用していますか? あなたはあなたのコードを見ていると思います。

その場合は、ストアを で定義しapp/store/Images.jsapp.jsそのストアがあることをファイルに記述します。

Ext.application({
    name: 'Photoalbum',
    stores: ['Images']
});

そのストアを定義してapp.jsファイルに含めたので、その名前を使用していつでもアクセスできます。

{
    xtype: 'list',
    store: 'Images',
    ...
}

そのストアのインスタンスを再作成しないでください。これは (アプリケーションによって) 1 回だけ作成する必要があり、その後、ストアの文字列バージョンを使用できます。

また、簡単な注意として、コンストラクターをオーバーライドすることは非常に悪い習慣です。代わりに、initializeメソッドをオーバーライドする必要があります。

于 2012-02-12T22:31:30.343 に答える