简体   繁体   English

ExtJs 3组合框设置默认值

[英]ExtJs 3 combobox setting default value

I am new to ExtJS.. a few weeks old, so please pardon me if this seems to be a trivial query. 我是ExtJS的新手..几周大了,所以如果这看起来很简单,请原谅我。

I have to load the list of values in a combo box (SourceSystem) based on value selected in another combo box (DeliveryMethod). 我必须根据在另一个组合框(DeliveryMethod)中选择的值在组合框(SourceSystem)中加载值列表。 I am using JSON stores for both the combos. 我正在为两个组合使用JSON存储。

So I have added a listener on combobox 2 as 所以我在组合框2上添加了一个监听器

listeners:{
     'select': function(combo, record,index) {
      selectedDelMethod = record.data.codeValue;
      var srcSystem = Ext.getCmp('sourceSystemCombo');
      srcSystem.reset();
      srcSystem.store.reload({ 
      params: {
        attrID: 3002,
        delvMethod: selectedDelMethod

        }
      });        
   }

Here, the srcSystem.store loads different list based on selectedDelMethod. 在这里,srcSystem.store基于selectedDelMethod加载不同的列表。 This is working fine. 一切正常。 But when the SourceSystem combox id loaded, it is populated, but nothing is shown as default value. 但是,当加载SourceSystem combox ID时,将填充它,但是没有任何内容显示为默认值。

fieldLabel:     'Source System',
id:        'sourceSystemCombo',
xtype:          'combo',
mode:           'local',
triggerAction:  'all',
forceSelection: true,
editable:       false,
name:           'sourceSystem',
displayField:   'shortDescription',
valueField:     'codeValue',
hiddenName:     'sourceSystem',
store:          sourceSystemStore,  
listeners: {
   'afterrender': function(combo){
    var selectedRecord = combo.getStore().getAt(0);
    combo.setValue(selectedRecord);        
  }
}

I am sure I am missing something in the afterrender listener. 我确定我在售后监听器中缺少某些内容。 Please tell me how can I get the first value to be the default value? 请告诉我如何将第一个值设为默认值?

I found that the combo.getStore().getAt(0) was returning null. 我发现combo.getStore()。getAt(0)返回null。 After trying couple of methods I managed to resolve the problem. 在尝试了几种方法之后,我设法解决了问题。 Instead of putting an event on combobox, I updated the reload of store to set first value in combo. 我没有在组合框上放置事件,而是更新了商店的重载以在组合框中设置第一个值。 Here is the 这里是

var srcSystem = Ext.getCmp('sourceSystemCombo');
srcSystem.reset();
srcSystem.store.reload({ 
    params: {
        attrID:     3002,
        delvMethod: selectedDelMethod
    },
    scope : this,
    callback : function(records, operation, success){
        srcSystem.setValue(srcSystem.store.getAt(0).get('codeValue'));
    }
});  

The setting value on combobox has to be a callback function on store as loading of store is an asynch process. 组合框上的设置值必须是商店上的回调函数,因为商店的加载是一个异步过程。 see this ! 看到这个

Try using 尝试使用
this.fireEvent('select',combo,selectedRecord) instead of this.fireEvent('select',combo,selectedRecord)代替
combo.setValue(selectedRecord); combo.setValue(selectedRecord);

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

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