加载comboBox extjs的默认值

cra*_*ies 6 javascript combobox extjs store

如何从我的json商店(远程)加载一个默认值到一个组合框,我试着在渲染组合之前加载商店,并使用setValue()我希望我的组合在商店中显示第一个结果plz告诉我正确的方法和thanx

Mch*_*chl 14

您需要在value加载存储后将属性设置为第一个元素的值

Ext.ns('MyNamespace');

MyNamespace.MyComboBox = Ext.extend(Ext.form.ComboBox, {
  displayField: 'displayValue',
  triggerAction: 'all',
  valueField: 'ID',

  initComponent: function () {
    this.store = new Ext.data.JsonStore({
      url: 'url',
      baseParams: {
        //params
      },
      fields: [
        {name:'ID', mapping: 'ID', type: 'int'},
        {name:'displayValue', mapping: 'displayValue', type: 'string'},
      ],
      root: 'root'
    });

    var me = this;
    this.store.on('load',function(store) {
      me.setValue(store.getAt(0).get('ID'));
    })

    MyNamespace.MyComboBox.superclass.initComponent.call(this);

    this.store.load();
  }

});
Run Code Online (Sandbox Code Playgroud)