6

如何将我的 json 存储(远程)中的默认值加载到组合框中,我尝试在渲染组合之前加载存储,并使用 setValue() 我希望我的组合在存储中显示第一个结果请告诉我这样做的正确方法和thanx

4

1 回答 1

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

});
于 2010-08-15T21:10:01.200 回答