简体   繁体   English

ExtJS:一次加载所有商店

[英]ExtJS: All stores loading at once

My application.js file is defined as shown below. 我的application.js文件的定义如下所示。 As you can see, there are a lot of stores and views to load. 如您所见,有很多商店和视图要加载。

The problem is, they are loaded asynchronously. 问题是,它们是异步加载的。 So, if a user clicks a button before the store has been loaded, it will not work. 因此,如果用户在商店被加载之前单击一个按钮,它将无法工作。

If I wait until all stores have been loaded, it will work as intended. 如果我等到所有商店都加载完毕,它将按预期工作。

How can I only load a store when it is required; 我如何只在需要时加载商店; or, what is a better solution to this problem? 或者,什么是对此问题的更好解决方案?

Ext.define('RateManagement.Application', {
    name: 'RateManagement',

    extend: 'Ext.app.Application',

    views: [
        // TODO: add views here
        'RateManagement.view.Grids.CountryRateGrid',
        'RateManagement.view.Grids.LocationRateGrid',
        'RateManagement.view.ComboBox.CountryCombo',
        'RateManagement.view.ComboBox.CurrencyCombo',
        'RateManagement.view.ComboBox.LocationCombo',
        'RateManagement.view.ComboBox.RateTypeCombo',
        'RateManagement.view.Columns.CurrencyColumn',
        'RateManagement.view.Columns.RateTypeColumn',
        'RateManagement.view.Columns.LocationColumn',
        'RateManagement.view.Columns.RateTypeColumn',
        'RateManagement.view.Columns.CountryColumn',
        'RateManagement.view.ServiceSelect.ServiceSelect',
        'RateManagement.view.Grids.AirShipmentGrid',
        'RateManagement.view.Grids.LocationWithYearOtherRateGrid',
        'RateManagement.view.Grids.CountryWithYearOtherRateGrid',
        'RateManagement.view.Grids.RealtorFeeRateGrid',
        'RateManagement.view.Grids.AirfareRateGrid'
    ],

    controllers: [
        // TODO: add controllers here
    ],

    stores: [
        // TODO: add stores here
        'RateManagement.store.CountryStore',
        'RateManagement.store.CurrencyStore',
        'RateManagement.store.LocationStore',
        'RateManagement.store.RateTypeStore',
        'RateManagement.store.LegalRateStore',
        'RateManagement.store.DeparturePackageRateStore',
        'RateManagement.store.HouseSearchStore',
        'RateManagement.store.LanguageTrainingStore',
        'RateManagement.store.TempLiving1BedroomStore',
        'RateManagement.store.TempLiving2BedroomStore',
        'RateManagement.store.TempLiving3BedroomStore',
        'RateManagement.store.TransportationLuxury',
        'RateManagement.store.TransportationMidSize',
        'RateManagement.store.LanguageTrainingStore',
        'RateManagement.store.AirShipmentStore',
        'RateManagement.store.ServiceStore',
        'RateManagement.store.HomeSearchTripLodgingStore',
        'RateManagement.store.HomeSearchTripCarRentalStore',
        'RateManagement.store.HomeSearchTripMealsStore',
        'RateManagement.store.SchoolSearchStore',
        'RateManagement.store.RealtorFeeStore',
        'RateManagement.store.AirfareStore'
    ],

    models: [
        'RateManagement.model.Country',
        'RateManagement.model.Currency',
        'RateManagement.model.Location',
        'RateManagement.model.CountryRate',
        'RateManagement.model.LocationRate',
        'RateManagement.model.CountryRate',
        'RateManagement.model.Service',
        'RateManagement.model.AirShipmentModel',
        'RateManagement.model.RealtorFeeModel',
        'RateManagement.model.AirfareRate'
    ],

    launch: function() {
        //app launch code

        //stupid fix for stupid bug
        Ext.override(Ext.grid.RowEditor,{

          addFieldsForColumn: function(column, initial) {
            var me = this,
                i,
                length, field;


            if (Ext.isArray(column)) {
                for (i = 0, length = column.length; i < length; i++) {
                    me.addFieldsForColumn(column[i], initial);
                }
                return;
            }


            if (column.getEditor) {


              field = column.getEditor(null, {
                  xtype: 'displayfield',
                  getModelData: function() {
                      return null;
                  }
              });
              if (column.align === 'right') {
                  field.fieldStyle = 'text-align:right';
              }


              if (column.xtype === 'actioncolumn') {
                  field.fieldCls += ' ' + Ext.baseCSSPrefix + 'form-action-col-field';
              }


              if (me.isVisible() && me.context) {
                  if (field.is('displayfield')) {
                      me.renderColumnData(field, me.context.record, column);
                  } else {
                      field.suspendEvents();
                      field.setValue(me.context.record.get(column.dataIndex));
                      field.resumeEvents();
                  }
              }
              if (column.hidden) {
                  me.onColumnHide(column);
              } else if (column.rendered && !initial) {
                  me.onColumnShow(column);
              }

              // -- start edit
              me.mon(field, 'change', me.onFieldChange, me);
              // -- end edit
            }
          }
        });
    }
});

You should consider using controllers: http://docs-origin.sencha.com/extjs/4.2.1/#!/api/Ext.app.Controller 您应该考虑使用控制器: http : //docs-origin.sencha.com/extjs/4.2.1/#!/api/Ext.app.Controller

With controllers you can split your application bootstrap class in multiple small controllers which were invoked and loaded when needed. 使用控制器,您可以将应用程序引导程序类拆分为多个小型控制器,这些控制器在需要时会被调用和加载。 They can have depenencies to models, stores and views which will be loaded when a new instance of the controller is created (eg when a user requests opening a new window). 它们可以依赖于模型,存储和视图,这些关系将在创建控制器的新实例时(例如,当用户请求打开新窗口时)加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM