Extjs 4.1等待商店加载窗口中的多个组合框

时间:2013-07-26 04:28:13

标签: extjs combobox load store

我正在使用ExtJS 4.1。我正在尝试等待组合框的所有商店加载。我在听窗前的事件。

如果未定义组合框计数,则获取所有组合框,保存计数,加载存储并注册减少组合框计数的回调。当计数变为零时,它会调用show方法,并显示窗口。

如果定义了组合框计数,那么如果它为零,我返回true以允许窗口显示,否则我返回false。

然而,问题是并非所有组合框都显示displayValue,并显示 改为valueField。

    console.log('--- onWindowBeforeRender');

if (typeof this.comboboxCount != 'undefined') {
    if (this.comboboxCount == 0) {
        console.log('returning true:');
        return true;
    }
    else {
        console.log('returning false1:');
        return false;
    }
}

var x = component.query('combobox');

console.log('x.length:');
console.log(x.length);

this.comboboxCount = x.length;

for (var i = 0; i < x.length; i++) {
    var y = x[i];

    console.log('y:'+i);
    console.log(y);

    y.store.load({
        scope: this,
        callback: function(records, operation, success) {
            this.comboboxCount--;

            console.log('comboboxCount:' + this.comboboxCount);
            if (!this.comboboxCount) {
                console.log('all stores loaded.');
                this.show();
           }
        }
    });
}
console.log('returning false2');
return false;

以下是组合框的代码:

                    {
                        xtype: 'combobox',
                        anchor: '100%',
                        fieldLabel: 'Region',
                        name: 'region_id',
                        displayField: 'name',
                        store: 'RegionStore',
                        valueField: 'id'
                    },
                    {
                        xtype: 'combobox',
                        anchor: '100%',
                        fieldLabel: 'Country',
                        name: 'country_id',
                        displayField: 'name',
                        store: 'CountryStore',
                        valueField: 'id'
                    }

以下是商店:

Ext.define('RR.store.CountryStore', {
  extend: 'Ext.data.Store',

  requires: [
  'RR.model.CountryModel'
  ],

  constructor: function(cfg) {
  var me = this;
  cfg = cfg || {};
  me.callParent([Ext.apply({
      model: 'RR.model.CountryModel',
      storeId: 'CountryStore',
      proxy: {
      type: 'ajax',
      api: {
          create: '/country/create',
          read: '/country/read',
          update: '/country/update'
      },
      reader: {
          type: 'json',
          root: 'countrys'
      }
      }
  }, cfg)]);
  }
});

Ext.define('RR.store.RegionStore', {
  extend: 'Ext.data.Store',

  requires: [
  'RR.model.RegionModel'
  ],

  constructor: function(cfg) {
  var me = this;
  cfg = cfg || {};
  me.callParent([Ext.apply({
      model: 'RR.model.RegionModel',
      storeId: 'RegionStore',
      proxy: {
      type: 'ajax',
      api: {
          create: '/region/create',
          read: '/region/read',
          update: '/region/update'
      },
      reader: {
          type: 'json',
          root: 'regions'
      }
      }
  }, cfg)]);
  }
});

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题。组合框的商店一次只请求25条记录。并非所有记录都已加载。因此找不到id,并且displayField的值被设置为valueField。

更改服务器端代码以忽略启动/限制解决了问题。

从商店的文档:

  

如果这个商店是缓冲的,这只能找到发生的记录       要缓存在页面缓存中。这将是数据集的一部分       如果是当前可见区域或最近访问过的区域       页面尚未从缓存中清除