最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Load default value for a comboBox extjs - Stack Overflow

programmeradmin0浏览0评论

how can i load a default value from my json store (remote) into a combobox , i've tried load the store before render the combo , and use setValue() i want my combo to display the first result in the store plz tell me the right way to do this and thanx

how can i load a default value from my json store (remote) into a combobox , i've tried load the store before render the combo , and use setValue() i want my combo to display the first result in the store plz tell me the right way to do this and thanx

Share Improve this question asked Aug 15, 2010 at 20:48 cranberiescranberies 4413 gold badges9 silver badges23 bronze badges 1
  • Possible duplicate of Extjs 4 combobox default value – Vadzim Commented Apr 24, 2018 at 10:32
Add a comment  | 

1 Answer 1

Reset to default 14

You need to set the value property to the value of the first element after the store is loaded

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

});
发布评论

评论列表(0)

  1. 暂无评论