简体   繁体   English

EXTJS 4:如何在不确定组合框ID的情况下获取组合框值

[英]EXTJS 4 : how to get combobox value with out determine combobox id

var StaticComboBox = Ext.define('MyApp.view.ComboBoxType', {
  extend: 'Ext.form.ComboBox',
  mode: 'local',
  fieldLabel: 'Type',
  labelWidth: 50,
  triggerAction: 'all',
  editable: false,
  valueField: 'value',
  displayField: 'label', 
  data: [
               {value: 0, label: 'By Vehicle'},  {value: 1, label: 'By Route'}
          ] ,
  initComponent: function() {
    this.store = new Ext.data.Store({
      fields: ['value', 'label'],
      data: this.data
    });
    StaticComboBox.superclass.initComponent.call(this);
  },
  listeners: {
        change: function (combo, value) {
        var grid = Ext.ComponentQuery.query('dailywindow gridpanel[name=mydailychartgrid]')[0];
        if (grid != null){
            if (value == 0) {
            //grid.reconfigure(VehicleStore_Chart,VehicleModel)
            grid.reconfigure(VehicleStore_Chart);
            grid.columns[1].setText('Plat No');
            grid.columns[1].dataIndex = "Plat_No"
            grid.columns[1].width = 100
            }else{

            //grid.reconfigure(RouteNameStore_DailyChart,RouteModel)
            grid.reconfigure(RouteNameStore_DailyChart)
            grid.columns[1].setText('Route Code');
            grid.columns[1].dataIndex = "Route_Code"
            grid.columns[1].width = 100
            }
        }
        //alert(value);
        }
  }

});

var c = new StaticComboBox();
c.setValue(0);

how do i get the combobox value without using determine id in combobox ? 如何在不使用combobox的确定ID的情况下获取combobox的值?
Ext.getCmp("ComboBoxType").getValue() does not work. Ext.getCmp("ComboBoxType").getValue()不起作用。

if you don't want to use an id, use itemId instead. 如果您不想使用ID,请改用itemId

var val = Ext.ComponentQuery.query('ComboBoxType#yourItemId')[0].getValue();

the advantage of itemId is that they don't need to be unique. itemId的优点是它们不需要唯一。

Yes, you should add 'id' property to combobox and then use the 'Ext.getCmp('componentId')' 是的,您应该将'id'属性添加到组合框,然后使用'Ext.getCmp('componentId')'

or 要么

Assign 'name' property to it and use the componentquery . 给它分配'name'属性,并使用componentquery

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

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