【问题标题】:ExtJs 3 combobox setting default valueExtJs 3组合框设置默认值
【发布时间】:2013-04-17 11:53:04
【问题描述】:

我是 ExtJS 的新手。几周前,如果这似乎是一个微不足道的查询,请原谅我。

我必须根据在另一个组合框 (DeliveryMethod) 中选择的值加载组合框 (SourceSystem) 中的值列表。我对这两个组合都使用 JSON 存储。

所以我在组合框 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

        }
      });        
   }

这里,srcSystem.store 根据 selectedDelMethod 加载不同的列表。 这工作正常。但是当 SourceSystem 组合框 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);        
  }
}

我确定我在 afterrender 监听器中遗漏了一些东西。请告诉我如何让第一个值成为默认值?

【问题讨论】:

  • combo.getStore().getAt(0) 将返回数据记录,而combo.setValue() 接受字符串值引用:docs.sencha.com/extjs/3.4.0/#!/api/… 尝试从记录中获取值,例如 record.data.value

标签: java javascript extjs


【解决方案1】:

我发现 combo.getStore().getAt(0) 返回 null。在尝试了几种方法后,我设法解决了这个问题。我没有在组合框上放置一个事件,而是更新了商店的重新加载以设置组合中的第一个值。这里是

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'));
    }
});  

combobox 上的设置值必须是 store 上的回调函数,因为 store 的加载是一个异步过程。见this

【讨论】:

    【解决方案2】:

    尝试使用
    this.fireEvent('select',combo,selectedRecord) 而不是
    combo.setValue(selectedRecord);

    【讨论】:

      猜你喜欢
      • 2011-08-23
      • 2014-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-30
      • 2015-02-08
      • 2017-10-03
      相关资源
      最近更新 更多