【问题标题】:Unable to listen to load event in the controller无法监听控制器中的加载事件
【发布时间】:2015-08-25 07:24:45
【问题描述】:

我在 stackoverflow 上扫描了许多线程(thisthis),但没有一个可以帮助我解决问题。所以,我有一个这样定义的商店:

Ext.define('fileseditor.store.fileseditorNavigStore',{
    extend:'Ext.data.TreeStore',
    ...

我听说过 getter 并尝试在我的控制器中执行此操作:

init: function(){
    this.getfileseditorNavigStoreStore().addListener('load', this.finishedLoading, this);

但这会导致错误this.getfileseditorNavigStoreStore is not a function

【问题讨论】:

    标签: extjs model-view-controller


    【解决方案1】:

    这样做是这样的:

    http://docs.sencha.com/extjs/4.2.3/#!/api/Ext.app.Controller-cfg-stores

    编写你自己的getter:

     Ext.define("MyApp.controller.Foo", {
         extend: "Ext.app.Controller",
    
         requires: [
             'MyApp.store.Users',
             'MyApp.store.Vehicles'
         ]
    
         getUsersStore: function() {
             return this.getStore("Users");
         },
    
         getVehiclesStore: function() {
             return this.getStore("Vehicles");
         }
     });
    

    或者更短

    Ext.define("MyApp.controller.Foo", {
         extend: "Ext.app.Controller",
         stores: ['Users', 'Vehicles']
     });
    

    =>您可以使用 de storeId 或 fullName (fileseditor.store.fileseditorNavigStore)

    更新

    在控制器中监听事件的另一种方式是这样的:

    http://docs.sencha.com/extjs/4.2.3/#!/api/Ext.app.Controller-method-listen

    使用 storeId="myStoreId" 监听 Store 触发的“加载”事件:

     Ext.define('AM.controller.Users', {
         init: function() {
             this.listen({
                 store: {
                     '#myStoreId': {
                         load: this.onMyStoreLoad
                     }
                 }
             });
         },
         ...
     });
    

    顺便说一句:按照惯例,顶级命名空间和实际的类名应该是 CamelCased,其他一切都应该是小写的。所以FilesEditor.store.FilesEditorNaviagStore

    【讨论】:

    • 谢谢您,先生!这对我帮助很大!
    【解决方案2】:
     var me = this;
     var filesEditorStore = Ext.create( 'fileseditor.store.fileseditorNavigStore' , {
            storeId : 'fileseditor'
        } );
    
      filesEditorStore.on( 'load' , function ( store , records , successful , eOpts ) {
            if ( successful ) { 
                me.finishedLoading();
            }
        } );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-03
      • 1970-01-01
      • 1970-01-01
      • 2013-08-16
      • 1970-01-01
      • 2011-11-03
      相关资源
      最近更新 更多